uint32_t nr_zones;
struct fio_zone_info *p;
uint64_t zone_size = td->o.zone_size;
+ uint64_t zone_capacity = td->o.zone_capacity;
struct zoned_block_device_info *zbd_info = NULL;
int i;
return 1;
}
+ if (zone_capacity == 0)
+ zone_capacity = zone_size;
+
+ if (zone_capacity > zone_size) {
+ log_err("%s: job parameter zonecapacity %llu is larger than zone size %llu\n",
+ f->file_name, (unsigned long long) td->o.zone_capacity,
+ (unsigned long long) td->o.zone_size);
+ return 1;
+ }
+
nr_zones = (f->real_file_size + zone_size - 1) / zone_size;
zbd_info = scalloc(1, sizeof(*zbd_info) +
(nr_zones + 1) * sizeof(zbd_info->zone_info[0]));
p->wp = p->start;
p->type = ZBD_ZONE_TYPE_SWR;
p->cond = ZBD_ZONE_COND_EMPTY;
- p->capacity = zone_size;
+ p->capacity = zone_capacity;
}
/* a sentinel */
p->start = nr_zones * zone_size;
return 0;
}
+static unsigned int zbd_zone_nr(struct zoned_block_device_info *zbd_info,
+ struct fio_zone_info *zone)
+{
+ return zone - zbd_info->zone_info;
+}
+
/**
- * zbd_reset_range - reset zones for a range of sectors
+ * zbd_reset_zone - reset the write pointer of a single zone
* @td: FIO thread data.
- * @f: Fio file for which to reset zones
- * @sector: Starting sector in units of 512 bytes
- * @nr_sectors: Number of sectors in units of 512 bytes
+ * @f: FIO file associated with the disk for which to reset a write pointer.
+ * @z: Zone to reset.
*
* Returns 0 upon success and a negative error code upon failure.
+ *
+ * The caller must hold z->mutex.
*/
-static int zbd_reset_range(struct thread_data *td, struct fio_file *f,
- uint64_t offset, uint64_t length)
+static int zbd_reset_zone(struct thread_data *td, struct fio_file *f,
+ struct fio_zone_info *z)
{
- uint32_t zone_idx_b, zone_idx_e;
- struct fio_zone_info *zb, *ze, *z;
+ uint64_t offset = z->start;
+ uint64_t length = (z+1)->start - offset;
int ret = 0;
assert(is_valid_offset(f, offset + length - 1));
+ dprint(FD_ZBD, "%s: resetting wp of zone %u.\n", f->file_name,
+ zbd_zone_nr(f->zbd_info, z));
switch (f->zbd_info->model) {
case ZBD_HOST_AWARE:
case ZBD_HOST_MANAGED:
break;
}
- zone_idx_b = zbd_zone_idx(f, offset);
- zb = &f->zbd_info->zone_info[zone_idx_b];
- zone_idx_e = zbd_zone_idx(f, offset + length);
- ze = &f->zbd_info->zone_info[zone_idx_e];
- for (z = zb; z < ze; z++) {
- pthread_mutex_lock(&z->mutex);
- pthread_mutex_lock(&f->zbd_info->mutex);
- f->zbd_info->sectors_with_data -= z->wp - z->start;
- pthread_mutex_unlock(&f->zbd_info->mutex);
- z->wp = z->start;
- z->verify_block = 0;
- pthread_mutex_unlock(&z->mutex);
- }
+ pthread_mutex_lock(&f->zbd_info->mutex);
+ f->zbd_info->sectors_with_data -= z->wp - z->start;
+ pthread_mutex_unlock(&f->zbd_info->mutex);
+ z->wp = z->start;
+ z->verify_block = 0;
- td->ts.nr_zone_resets += ze - zb;
+ td->ts.nr_zone_resets++;
return ret;
}
-static unsigned int zbd_zone_nr(struct zoned_block_device_info *zbd_info,
- struct fio_zone_info *zone)
-{
- return zone - zbd_info->zone_info;
-}
-
-/**
- * zbd_reset_zone - reset the write pointer of a single zone
- * @td: FIO thread data.
- * @f: FIO file associated with the disk for which to reset a write pointer.
- * @z: Zone to reset.
- *
- * Returns 0 upon success and a negative error code upon failure.
- */
-static int zbd_reset_zone(struct thread_data *td, struct fio_file *f,
- struct fio_zone_info *z)
-{
- dprint(FD_ZBD, "%s: resetting wp of zone %u.\n", f->file_name,
- zbd_zone_nr(f->zbd_info, z));
-
- return zbd_reset_range(td, f, z->start, zbd_zone_end(z) - z->start);
-}
-
/* The caller must hold f->zbd_info->mutex */
static void zbd_close_zone(struct thread_data *td, const struct fio_file *f,
unsigned int open_zone_idx)
f->last_pos[ddir] >= zbd_zone_capacity_end(z)) {
dprint(FD_ZBD,
"%s: Jump from zone capacity limit to zone end:"
- " (%lu -> %lu) for zone %u (%ld)\n",
- f->file_name, f->last_pos[ddir], zbd_zone_end(z),
- zbd_zone_nr(f->zbd_info, z), z->capacity);
+ " (%llu -> %llu) for zone %u (%llu)\n",
+ f->file_name, (unsigned long long) f->last_pos[ddir],
+ (unsigned long long) zbd_zone_end(z),
+ zbd_zone_nr(f->zbd_info, z),
+ (unsigned long long) z->capacity);
td->io_skip_bytes += zbd_zone_end(z) - f->last_pos[ddir];
f->last_pos[ddir] = zbd_zone_end(z);
}