Lines Matching +full:a +full:- +full:z

1 // SPDX-License-Identifier: GPL-2.0
32 * Get the name of a zone group directory.
51 struct zonefs_zone *z) in zonefs_account_active() argument
55 if (zonefs_zone_is_cnv(z)) in zonefs_account_active()
62 if (z->z_flags & (ZONEFS_ZONE_OFFLINE | ZONEFS_ZONE_READONLY)) in zonefs_account_active()
69 if ((z->z_flags & ZONEFS_ZONE_OPEN) || in zonefs_account_active()
70 (z->z_wpoffset > 0 && z->z_wpoffset < z->z_capacity)) { in zonefs_account_active()
71 if (!(z->z_flags & ZONEFS_ZONE_ACTIVE)) { in zonefs_account_active()
72 z->z_flags |= ZONEFS_ZONE_ACTIVE; in zonefs_account_active()
73 atomic_inc(&sbi->s_active_seq_files); in zonefs_account_active()
80 if (z->z_flags & ZONEFS_ZONE_ACTIVE) { in zonefs_account_active()
81 z->z_flags &= ~ZONEFS_ZONE_ACTIVE; in zonefs_account_active()
82 atomic_dec(&sbi->s_active_seq_files); in zonefs_account_active()
87 * Manage the active zone count. Called with zi->i_truncate_mutex held.
91 lockdep_assert_held(&ZONEFS_I(inode)->i_truncate_mutex); in zonefs_inode_account_active()
93 return zonefs_account_active(inode->i_sb, zonefs_inode_zone(inode)); in zonefs_inode_account_active()
97 * Execute a zone management operation.
100 struct zonefs_zone *z, enum req_op op) in zonefs_zone_mgmt() argument
112 if (op == REQ_OP_ZONE_CLOSE && !z->z_wpoffset) in zonefs_zone_mgmt()
115 trace_zonefs_zone_mgmt(sb, z, op); in zonefs_zone_mgmt()
116 ret = blkdev_zone_mgmt(sb->s_bdev, op, z->z_sector, in zonefs_zone_mgmt()
117 z->z_size >> SECTOR_SHIFT); in zonefs_zone_mgmt()
121 blk_op_str(op), z->z_sector, ret); in zonefs_zone_mgmt()
130 lockdep_assert_held(&ZONEFS_I(inode)->i_truncate_mutex); in zonefs_inode_zone_mgmt()
132 return zonefs_zone_mgmt(inode->i_sb, zonefs_inode_zone(inode), op); in zonefs_inode_zone_mgmt()
137 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_i_size_write() local
142 * A full zone is no longer open/active and does not need in zonefs_i_size_write()
145 if (isize >= z->z_capacity) { in zonefs_i_size_write()
146 struct zonefs_sb_info *sbi = ZONEFS_SB(inode->i_sb); in zonefs_i_size_write()
148 if (z->z_flags & ZONEFS_ZONE_ACTIVE) in zonefs_i_size_write()
149 atomic_dec(&sbi->s_active_seq_files); in zonefs_i_size_write()
150 z->z_flags &= ~(ZONEFS_ZONE_OPEN | ZONEFS_ZONE_ACTIVE); in zonefs_i_size_write()
156 struct super_block *sb = inode->i_sb; in zonefs_update_stats()
164 spin_lock(&sbi->s_lock); in zonefs_update_stats()
171 nr_blocks = (old_isize - new_isize) >> sb->s_blocksize_bits; in zonefs_update_stats()
172 if (sbi->s_used_blocks > nr_blocks) in zonefs_update_stats()
173 sbi->s_used_blocks -= nr_blocks; in zonefs_update_stats()
175 sbi->s_used_blocks = 0; in zonefs_update_stats()
177 sbi->s_used_blocks += in zonefs_update_stats()
178 (new_isize - old_isize) >> sb->s_blocksize_bits; in zonefs_update_stats()
179 if (sbi->s_used_blocks > sbi->s_blocks) in zonefs_update_stats()
180 sbi->s_used_blocks = sbi->s_blocks; in zonefs_update_stats()
183 spin_unlock(&sbi->s_lock); in zonefs_update_stats()
187 * Check a zone condition. Return the amount of written (and still readable)
191 struct zonefs_zone *z, in zonefs_check_zone_condition() argument
194 switch (zone->cond) { in zonefs_check_zone_condition()
197 z->z_sector); in zonefs_check_zone_condition()
198 z->z_flags |= ZONEFS_ZONE_OFFLINE; in zonefs_check_zone_condition()
202 * The write pointer of read-only zones is invalid, so we cannot in zonefs_check_zone_condition()
205 * (wpoffset == 0) on mount. For a runtime error, this keeps in zonefs_check_zone_condition()
209 zonefs_warn(sb, "Zone %llu: read-only zone\n", in zonefs_check_zone_condition()
210 z->z_sector); in zonefs_check_zone_condition()
211 z->z_flags |= ZONEFS_ZONE_READONLY; in zonefs_check_zone_condition()
212 if (zonefs_zone_is_cnv(z)) in zonefs_check_zone_condition()
213 return z->z_capacity; in zonefs_check_zone_condition()
214 return z->z_wpoffset; in zonefs_check_zone_condition()
217 return z->z_capacity; in zonefs_check_zone_condition()
219 if (zonefs_zone_is_cnv(z)) in zonefs_check_zone_condition()
220 return z->z_capacity; in zonefs_check_zone_condition()
221 return (zone->wp - zone->start) << SECTOR_SHIFT; in zonefs_check_zone_condition()
226 * Check a zone condition and adjust its inode access permissions for
231 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_inode_update_mode() local
233 if (z->z_flags & ZONEFS_ZONE_OFFLINE) { in zonefs_inode_update_mode()
235 inode->i_flags |= S_IMMUTABLE; in zonefs_inode_update_mode()
236 inode->i_mode &= ~0777; in zonefs_inode_update_mode()
237 } else if (z->z_flags & ZONEFS_ZONE_READONLY) { in zonefs_inode_update_mode()
239 inode->i_flags |= S_IMMUTABLE; in zonefs_inode_update_mode()
240 if (z->z_flags & ZONEFS_ZONE_INIT_MODE) in zonefs_inode_update_mode()
241 inode->i_mode &= ~0777; in zonefs_inode_update_mode()
243 inode->i_mode &= ~0222; in zonefs_inode_update_mode()
246 z->z_flags &= ~ZONEFS_ZONE_INIT_MODE; in zonefs_inode_update_mode()
247 z->z_mode = inode->i_mode; in zonefs_inode_update_mode()
253 struct blk_zone *z = data; in zonefs_io_error_cb() local
255 *z = *zone; in zonefs_io_error_cb()
262 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_handle_io_error() local
263 struct super_block *sb = inode->i_sb; in zonefs_handle_io_error()
269 * read-only), read errors are simply signaled to the IO issuer as long in zonefs_handle_io_error()
273 data_size = zonefs_check_zone_condition(sb, z, zone); in zonefs_handle_io_error()
275 if (!(z->z_flags & (ZONEFS_ZONE_READONLY | ZONEFS_ZONE_OFFLINE)) && in zonefs_handle_io_error()
280 * At this point, we detected either a bad zone or an inconsistency in zonefs_handle_io_error()
282 * For the latter case, the cause may be a write IO error or an external in zonefs_handle_io_error()
285 * a write operation partially failed and data was writen at the end in zonefs_handle_io_error()
286 * of the file. This can happen in the case of a large direct IO in zonefs_handle_io_error()
289 * this can happen with a deferred write error with the use of the in zonefs_handle_io_error()
291 * completions. Other possibilities are (a) an external corruption, in zonefs_handle_io_error()
293 * has a serious problem (e.g. firmware bug). in zonefs_handle_io_error()
301 inode->i_ino, isize, data_size); in zonefs_handle_io_error()
305 * errors=zone-ro and errors=zone-offline result in changing the in zonefs_handle_io_error()
306 * zone condition to read-only and offline respectively, as if the in zonefs_handle_io_error()
309 if ((z->z_flags & ZONEFS_ZONE_OFFLINE) || in zonefs_handle_io_error()
310 (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZOL)) { in zonefs_handle_io_error()
312 inode->i_ino); in zonefs_handle_io_error()
313 if (!(z->z_flags & ZONEFS_ZONE_OFFLINE)) in zonefs_handle_io_error()
314 z->z_flags |= ZONEFS_ZONE_OFFLINE; in zonefs_handle_io_error()
317 } else if ((z->z_flags & ZONEFS_ZONE_READONLY) || in zonefs_handle_io_error()
318 (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZRO)) { in zonefs_handle_io_error()
320 inode->i_ino); in zonefs_handle_io_error()
321 if (!(z->z_flags & ZONEFS_ZONE_READONLY)) in zonefs_handle_io_error()
322 z->z_flags |= ZONEFS_ZONE_READONLY; in zonefs_handle_io_error()
325 } else if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO && in zonefs_handle_io_error()
332 * If the filesystem is mounted with the explicit-open mount option, we in zonefs_handle_io_error()
334 * the read-only or offline condition, to avoid attempting an explicit in zonefs_handle_io_error()
337 if ((sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) && in zonefs_handle_io_error()
338 (z->z_flags & (ZONEFS_ZONE_READONLY | ZONEFS_ZONE_OFFLINE))) in zonefs_handle_io_error()
339 z->z_flags &= ~ZONEFS_ZONE_OPEN; in zonefs_handle_io_error()
342 * If error=remount-ro was specified, any error result in remounting in zonefs_handle_io_error()
343 * the volume as read-only. in zonefs_handle_io_error()
345 if ((sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO) && !sb_rdonly(sb)) { in zonefs_handle_io_error()
346 zonefs_warn(sb, "remounting filesystem read-only\n"); in zonefs_handle_io_error()
347 sb->s_flags |= SB_RDONLY; in zonefs_handle_io_error()
356 z->z_wpoffset = data_size; in zonefs_handle_io_error()
361 * When an file IO error occurs, check the file zone to see if there is a change
362 * in the zone condition (e.g. offline or read-only). For a failed write to a
369 struct zonefs_zone *z = zonefs_inode_zone(inode); in __zonefs_io_error() local
370 struct super_block *sb = inode->i_sb; in __zonefs_io_error()
376 * Conventional zone have no write pointer and cannot become read-only in __zonefs_io_error()
377 * or offline. So simply fake a report for a single or aggregated zone in __zonefs_io_error()
381 if (!zonefs_zone_is_seq(z)) { in __zonefs_io_error()
382 zone.start = z->z_sector; in __zonefs_io_error()
383 zone.len = z->z_size >> SECTOR_SHIFT; in __zonefs_io_error()
392 * Memory allocations in blkdev_report_zones() can trigger a memory in __zonefs_io_error()
393 * reclaim which may in turn cause a recursion into zonefs as well as in __zonefs_io_error()
395 * end up in a deadlock on the inode truncate mutex, while the latter in __zonefs_io_error()
400 ret = blkdev_report_zones(sb->s_bdev, z->z_sector, 1, in __zonefs_io_error()
406 inode->i_ino, ret); in __zonefs_io_error()
407 zonefs_warn(sb, "remounting filesystem read-only\n"); in __zonefs_io_error()
408 sb->s_flags |= SB_RDONLY; in __zonefs_io_error()
426 inode_init_once(&zi->i_vnode); in zonefs_alloc_inode()
427 mutex_init(&zi->i_truncate_mutex); in zonefs_alloc_inode()
428 zi->i_wr_refcnt = 0; in zonefs_alloc_inode()
430 return &zi->i_vnode; in zonefs_alloc_inode()
443 struct super_block *sb = dentry->d_sb; in zonefs_statfs()
447 buf->f_type = ZONEFS_MAGIC; in zonefs_statfs()
448 buf->f_bsize = sb->s_blocksize; in zonefs_statfs()
449 buf->f_namelen = ZONEFS_NAME_MAX; in zonefs_statfs()
451 spin_lock(&sbi->s_lock); in zonefs_statfs()
453 buf->f_blocks = sbi->s_blocks; in zonefs_statfs()
454 if (WARN_ON(sbi->s_used_blocks > sbi->s_blocks)) in zonefs_statfs()
455 buf->f_bfree = 0; in zonefs_statfs()
457 buf->f_bfree = buf->f_blocks - sbi->s_used_blocks; in zonefs_statfs()
458 buf->f_bavail = buf->f_bfree; in zonefs_statfs()
461 if (sbi->s_zgroup[t].g_nr_zones) in zonefs_statfs()
462 buf->f_files += sbi->s_zgroup[t].g_nr_zones + 1; in zonefs_statfs()
464 buf->f_ffree = 0; in zonefs_statfs()
466 spin_unlock(&sbi->s_lock); in zonefs_statfs()
468 buf->f_fsid = uuid_to_fsid(sbi->s_uuid.b); in zonefs_statfs()
482 {"remount-ro", ZONEFS_MNTOPT_ERRORS_RO},
483 {"zone-ro", ZONEFS_MNTOPT_ERRORS_ZRO},
484 {"zone-offline", ZONEFS_MNTOPT_ERRORS_ZOL},
491 fsparam_flag ("explicit-open", Opt_explicit_open),
497 struct zonefs_context *ctx = fc->fs_private; in zonefs_parse_param()
507 ctx->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK; in zonefs_parse_param()
508 ctx->s_mount_opts |= result.uint_32; in zonefs_parse_param()
511 ctx->s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN; in zonefs_parse_param()
514 return -EINVAL; in zonefs_parse_param()
522 struct zonefs_sb_info *sbi = ZONEFS_SB(root->d_sb); in zonefs_show_options()
524 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO) in zonefs_show_options()
525 seq_puts(seq, ",errors=remount-ro"); in zonefs_show_options()
526 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZRO) in zonefs_show_options()
527 seq_puts(seq, ",errors=zone-ro"); in zonefs_show_options()
528 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZOL) in zonefs_show_options()
529 seq_puts(seq, ",errors=zone-offline"); in zonefs_show_options()
530 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_REPAIR) in zonefs_show_options()
543 return -EPERM; in zonefs_inode_setattr()
551 * allow setting any write attributes on the sub-directories grouping in zonefs_inode_setattr()
554 if ((iattr->ia_valid & ATTR_MODE) && S_ISDIR(inode->i_mode) && in zonefs_inode_setattr()
555 (iattr->ia_mode & 0222)) in zonefs_inode_setattr()
556 return -EPERM; in zonefs_inode_setattr()
558 if (((iattr->ia_valid & ATTR_UID) && in zonefs_inode_setattr()
559 !uid_eq(iattr->ia_uid, inode->i_uid)) || in zonefs_inode_setattr()
560 ((iattr->ia_valid & ATTR_GID) && in zonefs_inode_setattr()
561 !gid_eq(iattr->ia_gid, inode->i_gid))) { in zonefs_inode_setattr()
567 if (iattr->ia_valid & ATTR_SIZE) { in zonefs_inode_setattr()
568 ret = zonefs_file_truncate(inode, iattr->ia_size); in zonefs_inode_setattr()
575 if (S_ISREG(inode->i_mode)) { in zonefs_inode_setattr()
576 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_inode_setattr() local
578 z->z_mode = inode->i_mode; in zonefs_inode_setattr()
579 z->z_uid = inode->i_uid; in zonefs_inode_setattr()
580 z->z_gid = inode->i_gid; in zonefs_inode_setattr()
592 const char *name = fname->name; in zonefs_fname_to_fno()
593 unsigned int len = fname->len; in zonefs_fname_to_fno()
600 * File names are always a base-10 number string without any in zonefs_fname_to_fno()
604 return -ENOENT; in zonefs_fname_to_fno()
607 return -ENOENT; in zonefs_fname_to_fno()
610 return c - '0'; in zonefs_fname_to_fno()
612 for (i = 0, rname = name + len - 1; i < len; i++, rname--) { in zonefs_fname_to_fno()
615 return -ENOENT; in zonefs_fname_to_fno()
616 fno += (c - '0') * shift; in zonefs_fname_to_fno()
626 struct zonefs_zone_group *zgroup = dir->i_private; in zonefs_get_file_inode()
627 struct super_block *sb = dir->i_sb; in zonefs_get_file_inode()
629 struct zonefs_zone *z; in zonefs_get_file_inode() local
635 fno = zonefs_fname_to_fno(&dentry->d_name); in zonefs_get_file_inode()
639 if (!zgroup->g_nr_zones || fno >= zgroup->g_nr_zones) in zonefs_get_file_inode()
640 return ERR_PTR(-ENOENT); in zonefs_get_file_inode()
642 z = &zgroup->g_zones[fno]; in zonefs_get_file_inode()
643 ino = z->z_sector >> sbi->s_zone_sectors_shift; in zonefs_get_file_inode()
646 return ERR_PTR(-ENOMEM); in zonefs_get_file_inode()
647 if (!(inode->i_state & I_NEW)) { in zonefs_get_file_inode()
648 WARN_ON_ONCE(inode->i_private != z); in zonefs_get_file_inode()
652 inode->i_ino = ino; in zonefs_get_file_inode()
653 inode->i_mode = z->z_mode; in zonefs_get_file_inode()
656 inode->i_uid = z->z_uid; in zonefs_get_file_inode()
657 inode->i_gid = z->z_gid; in zonefs_get_file_inode()
658 inode->i_size = z->z_wpoffset; in zonefs_get_file_inode()
659 inode->i_blocks = z->z_capacity >> SECTOR_SHIFT; in zonefs_get_file_inode()
660 inode->i_private = z; in zonefs_get_file_inode()
662 inode->i_op = &zonefs_file_inode_operations; in zonefs_get_file_inode()
663 inode->i_fop = &zonefs_file_operations; in zonefs_get_file_inode()
664 inode->i_mapping->a_ops = &zonefs_file_aops; in zonefs_get_file_inode()
665 mapping_set_large_folios(inode->i_mapping); in zonefs_get_file_inode()
678 struct inode *root = d_inode(sb->s_root); in zonefs_get_zgroup_inode()
681 ino_t ino = bdev_nr_zones(sb->s_bdev) + ztype + 1; in zonefs_get_zgroup_inode()
685 return ERR_PTR(-ENOMEM); in zonefs_get_zgroup_inode()
686 if (!(inode->i_state & I_NEW)) in zonefs_get_zgroup_inode()
689 inode->i_ino = ino; in zonefs_get_zgroup_inode()
691 inode->i_size = sbi->s_zgroup[ztype].g_nr_zones; in zonefs_get_zgroup_inode()
694 inode->i_private = &sbi->s_zgroup[ztype]; in zonefs_get_zgroup_inode()
697 inode->i_op = &zonefs_dir_inode_operations; in zonefs_get_zgroup_inode()
698 inode->i_fop = &zonefs_dir_operations; in zonefs_get_zgroup_inode()
709 struct super_block *sb = dir->i_sb; in zonefs_get_dir_inode()
711 const char *name = dentry->d_name.name; in zonefs_get_dir_inode()
718 if (dentry->d_name.len != 3) in zonefs_get_dir_inode()
719 return ERR_PTR(-ENOENT); in zonefs_get_dir_inode()
722 if (sbi->s_zgroup[ztype].g_nr_zones && in zonefs_get_dir_inode()
727 return ERR_PTR(-ENOENT); in zonefs_get_dir_inode()
737 if (dentry->d_name.len > ZONEFS_NAME_MAX) in zonefs_lookup()
738 return ERR_PTR(-ENAMETOOLONG); in zonefs_lookup()
740 if (dir == d_inode(dir->i_sb->s_root)) in zonefs_lookup()
751 struct super_block *sb = inode->i_sb; in zonefs_readdir_root()
754 ino_t base_ino = bdev_nr_zones(sb->s_bdev) + 1; in zonefs_readdir_root()
756 if (ctx->pos >= inode->i_size) in zonefs_readdir_root()
762 if (ctx->pos == 2) { in zonefs_readdir_root()
763 if (!sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones) in zonefs_readdir_root()
769 ctx->pos++; in zonefs_readdir_root()
772 if (ctx->pos == 3 && ztype != ZONEFS_ZTYPE_SEQ) { in zonefs_readdir_root()
777 ctx->pos++; in zonefs_readdir_root()
787 struct zonefs_zone_group *zgroup = inode->i_private; in zonefs_readdir_zgroup()
788 struct super_block *sb = inode->i_sb; in zonefs_readdir_zgroup()
790 struct zonefs_zone *z; in zonefs_readdir_zgroup() local
801 if (ctx->pos >= inode->i_size + 2) in zonefs_readdir_zgroup()
809 return -ENOMEM; in zonefs_readdir_zgroup()
811 for (f = ctx->pos - 2; f < zgroup->g_nr_zones; f++) { in zonefs_readdir_zgroup()
812 z = &zgroup->g_zones[f]; in zonefs_readdir_zgroup()
813 ino = z->z_sector >> sbi->s_zone_sectors_shift; in zonefs_readdir_zgroup()
814 fname_len = snprintf(fname, ZONEFS_NAME_MAX - 1, "%u", f); in zonefs_readdir_zgroup()
817 ctx->pos++; in zonefs_readdir_zgroup()
829 if (inode == d_inode(inode->i_sb->s_root)) in zonefs_readdir()
857 struct super_block *sb = zd->sb; in zonefs_get_zone_info_cb()
862 * and not exposed as a file. in zonefs_get_zone_info_cb()
873 switch (zone->type) { in zonefs_get_zone_info_cb()
875 if (sbi->s_features & ZONEFS_F_AGGRCNV) { in zonefs_get_zone_info_cb()
877 if (!(sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones) || in zonefs_get_zone_info_cb()
878 zone->start != zd->cnv_zone_start) in zonefs_get_zone_info_cb()
879 sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones++; in zonefs_get_zone_info_cb()
880 zd->cnv_zone_start = zone->start + zone->len; in zonefs_get_zone_info_cb()
883 sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones++; in zonefs_get_zone_info_cb()
888 sbi->s_zgroup[ZONEFS_ZTYPE_SEQ].g_nr_zones++; in zonefs_get_zone_info_cb()
891 zonefs_err(zd->sb, "Unsupported zone type 0x%x\n", in zonefs_get_zone_info_cb()
892 zone->type); in zonefs_get_zone_info_cb()
893 return -EIO; in zonefs_get_zone_info_cb()
896 memcpy(&zd->zones[idx], zone, sizeof(struct blk_zone)); in zonefs_get_zone_info_cb()
903 struct block_device *bdev = zd->sb->s_bdev; in zonefs_get_zone_info()
906 zd->zones = kvcalloc(bdev_nr_zones(bdev), sizeof(struct blk_zone), in zonefs_get_zone_info()
908 if (!zd->zones) in zonefs_get_zone_info()
909 return -ENOMEM; in zonefs_get_zone_info()
915 zonefs_err(zd->sb, "Zone report failed %d\n", ret); in zonefs_get_zone_info()
920 zonefs_err(zd->sb, "Invalid zone report (%d/%u zones)\n", in zonefs_get_zone_info()
922 return -EIO; in zonefs_get_zone_info()
930 kvfree(zd->zones); in zonefs_free_zone_info()
934 * Create a zone group and populate it with zone files.
941 struct zonefs_zone_group *zgroup = &sbi->s_zgroup[ztype]; in zonefs_init_zgroup()
943 struct zonefs_zone *z; in zonefs_init_zgroup() local
948 if (!zgroup->g_nr_zones) in zonefs_init_zgroup()
951 zgroup->g_zones = kvcalloc(zgroup->g_nr_zones, in zonefs_init_zgroup()
953 if (!zgroup->g_zones) in zonefs_init_zgroup()
954 return -ENOMEM; in zonefs_init_zgroup()
959 * and is not use to back a file. in zonefs_init_zgroup()
961 end = zd->zones + bdev_nr_zones(sb->s_bdev); in zonefs_init_zgroup()
962 for (zone = &zd->zones[1]; zone < end; zone = next) { in zonefs_init_zgroup()
968 if (WARN_ON_ONCE(n >= zgroup->g_nr_zones)) in zonefs_init_zgroup()
969 return -EINVAL; in zonefs_init_zgroup()
975 * aggregated together. If one offline or read-only zone is in zonefs_init_zgroup()
980 (sbi->s_features & ZONEFS_F_AGGRCNV)) { in zonefs_init_zgroup()
984 zone->len += next->len; in zonefs_init_zgroup()
985 zone->capacity += next->capacity; in zonefs_init_zgroup()
986 if (next->cond == BLK_ZONE_COND_READONLY && in zonefs_init_zgroup()
987 zone->cond != BLK_ZONE_COND_OFFLINE) in zonefs_init_zgroup()
988 zone->cond = BLK_ZONE_COND_READONLY; in zonefs_init_zgroup()
989 else if (next->cond == BLK_ZONE_COND_OFFLINE) in zonefs_init_zgroup()
990 zone->cond = BLK_ZONE_COND_OFFLINE; in zonefs_init_zgroup()
994 z = &zgroup->g_zones[n]; in zonefs_init_zgroup()
996 z->z_flags |= ZONEFS_ZONE_CNV; in zonefs_init_zgroup()
997 z->z_sector = zone->start; in zonefs_init_zgroup()
998 z->z_size = zone->len << SECTOR_SHIFT; in zonefs_init_zgroup()
999 if (z->z_size > bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT && in zonefs_init_zgroup()
1000 !(sbi->s_features & ZONEFS_F_AGGRCNV)) { in zonefs_init_zgroup()
1003 z->z_size, in zonefs_init_zgroup()
1004 bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT); in zonefs_init_zgroup()
1005 return -EINVAL; in zonefs_init_zgroup()
1008 z->z_capacity = min_t(loff_t, MAX_LFS_FILESIZE, in zonefs_init_zgroup()
1009 zone->capacity << SECTOR_SHIFT); in zonefs_init_zgroup()
1010 z->z_wpoffset = zonefs_check_zone_condition(sb, z, zone); in zonefs_init_zgroup()
1012 z->z_mode = S_IFREG | sbi->s_perm; in zonefs_init_zgroup()
1013 z->z_uid = sbi->s_uid; in zonefs_init_zgroup()
1014 z->z_gid = sbi->s_gid; in zonefs_init_zgroup()
1021 z->z_flags |= ZONEFS_ZONE_INIT_MODE; in zonefs_init_zgroup()
1023 sb->s_maxbytes = max(z->z_capacity, sb->s_maxbytes); in zonefs_init_zgroup()
1024 sbi->s_blocks += z->z_capacity >> sb->s_blocksize_bits; in zonefs_init_zgroup()
1025 sbi->s_used_blocks += z->z_wpoffset >> sb->s_blocksize_bits; in zonefs_init_zgroup()
1034 (zone->cond == BLK_ZONE_COND_IMP_OPEN || in zonefs_init_zgroup()
1035 zone->cond == BLK_ZONE_COND_EXP_OPEN)) { in zonefs_init_zgroup()
1036 ret = zonefs_zone_mgmt(sb, z, REQ_OP_ZONE_CLOSE); in zonefs_init_zgroup()
1041 zonefs_account_active(sb, z); in zonefs_init_zgroup()
1046 if (WARN_ON_ONCE(n != zgroup->g_nr_zones)) in zonefs_init_zgroup()
1047 return -EINVAL; in zonefs_init_zgroup()
1051 zgroup->g_nr_zones, in zonefs_init_zgroup()
1052 str_plural(zgroup->g_nr_zones)); in zonefs_init_zgroup()
1066 kvfree(sbi->s_zgroup[ztype].g_zones); in zonefs_free_zgroups()
1067 sbi->s_zgroup[ztype].g_zones = NULL; in zonefs_free_zgroups()
1072 * Create a zone group and populate it with zone files.
1121 return -ENOMEM; in zonefs_read_super()
1123 bio_init(&bio, sb->s_bdev, &bio_vec, 1, REQ_OP_READ); in zonefs_read_super()
1133 ret = -EINVAL; in zonefs_read_super()
1134 if (le32_to_cpu(super->s_magic) != ZONEFS_MAGIC) in zonefs_read_super()
1137 stored_crc = le32_to_cpu(super->s_crc); in zonefs_read_super()
1138 super->s_crc = 0; in zonefs_read_super()
1146 sbi->s_features = le64_to_cpu(super->s_features); in zonefs_read_super()
1147 if (sbi->s_features & ~ZONEFS_F_DEFINED_FEATURES) { in zonefs_read_super()
1149 sbi->s_features); in zonefs_read_super()
1153 if (sbi->s_features & ZONEFS_F_UID) { in zonefs_read_super()
1154 sbi->s_uid = make_kuid(current_user_ns(), in zonefs_read_super()
1155 le32_to_cpu(super->s_uid)); in zonefs_read_super()
1156 if (!uid_valid(sbi->s_uid)) { in zonefs_read_super()
1162 if (sbi->s_features & ZONEFS_F_GID) { in zonefs_read_super()
1163 sbi->s_gid = make_kgid(current_user_ns(), in zonefs_read_super()
1164 le32_to_cpu(super->s_gid)); in zonefs_read_super()
1165 if (!gid_valid(sbi->s_gid)) { in zonefs_read_super()
1171 if (sbi->s_features & ZONEFS_F_PERM) in zonefs_read_super()
1172 sbi->s_perm = le32_to_cpu(super->s_perm); in zonefs_read_super()
1174 if (memchr_inv(super->s_reserved, 0, sizeof(super->s_reserved))) { in zonefs_read_super()
1179 import_uuid(&sbi->s_uuid, super->s_uuid); in zonefs_read_super()
1202 if (!sbi->s_zgroup[ztype].g_nr_zones) in zonefs_get_zgroup_inodes()
1209 sbi->s_zgroup[ztype].g_inode = dir_inode; in zonefs_get_zgroup_inodes()
1224 if (sbi->s_zgroup[ztype].g_inode) { in zonefs_release_zgroup_inodes()
1225 iput(sbi->s_zgroup[ztype].g_inode); in zonefs_release_zgroup_inodes()
1226 sbi->s_zgroup[ztype].g_inode = NULL; in zonefs_release_zgroup_inodes()
1233 * sub-directories and files according to the device zone configuration and
1239 struct zonefs_context *ctx = fc->fs_private; in zonefs_fill_super()
1244 if (!bdev_is_zoned(sb->s_bdev)) { in zonefs_fill_super()
1245 zonefs_err(sb, "Not a zoned block device\n"); in zonefs_fill_super()
1246 return -EINVAL; in zonefs_fill_super()
1252 * ZONEFS_F_AGGRCNV which increases the maximum file size of a file in zonefs_fill_super()
1257 return -ENOMEM; in zonefs_fill_super()
1259 spin_lock_init(&sbi->s_lock); in zonefs_fill_super()
1260 sb->s_fs_info = sbi; in zonefs_fill_super()
1261 sb->s_magic = ZONEFS_MAGIC; in zonefs_fill_super()
1262 sb->s_maxbytes = 0; in zonefs_fill_super()
1263 sb->s_op = &zonefs_sops; in zonefs_fill_super()
1264 sb->s_time_gran = 1; in zonefs_fill_super()
1271 sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev)); in zonefs_fill_super()
1272 sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev)); in zonefs_fill_super()
1273 sbi->s_uid = GLOBAL_ROOT_UID; in zonefs_fill_super()
1274 sbi->s_gid = GLOBAL_ROOT_GID; in zonefs_fill_super()
1275 sbi->s_perm = 0640; in zonefs_fill_super()
1276 sbi->s_mount_opts = ctx->s_mount_opts; in zonefs_fill_super()
1278 atomic_set(&sbi->s_wro_seq_files, 0); in zonefs_fill_super()
1279 sbi->s_max_wro_seq_files = bdev_max_open_zones(sb->s_bdev); in zonefs_fill_super()
1280 atomic_set(&sbi->s_active_seq_files, 0); in zonefs_fill_super()
1281 sbi->s_max_active_seq_files = bdev_max_active_zones(sb->s_bdev); in zonefs_fill_super()
1287 zonefs_info(sb, "Mounting %u zones", bdev_nr_zones(sb->s_bdev)); in zonefs_fill_super()
1289 if (!sbi->s_max_wro_seq_files && in zonefs_fill_super()
1290 !sbi->s_max_active_seq_files && in zonefs_fill_super()
1291 sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { in zonefs_fill_super()
1294 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN; in zonefs_fill_super()
1303 ret = -ENOMEM; in zonefs_fill_super()
1308 inode->i_ino = bdev_nr_zones(sb->s_bdev); in zonefs_fill_super()
1309 inode->i_mode = S_IFDIR | 0555; in zonefs_fill_super()
1311 inode->i_op = &zonefs_dir_inode_operations; in zonefs_fill_super()
1312 inode->i_fop = &zonefs_dir_operations; in zonefs_fill_super()
1313 inode->i_size = 2; in zonefs_fill_super()
1316 if (sbi->s_zgroup[ztype].g_nr_zones) { in zonefs_fill_super()
1318 inode->i_size++; in zonefs_fill_super()
1322 sb->s_root = d_make_root(inode); in zonefs_fill_super()
1323 if (!sb->s_root) in zonefs_fill_super()
1327 * Take a reference on the zone groups directory inodes in zonefs_fill_super()
1363 struct zonefs_context *ctx = fc->fs_private; in zonefs_free_fc()
1375 struct zonefs_context *ctx = fc->fs_private; in zonefs_reconfigure()
1376 struct super_block *sb = fc->root->d_sb; in zonefs_reconfigure()
1377 struct zonefs_sb_info *sbi = sb->s_fs_info; in zonefs_reconfigure()
1379 sync_filesystem(fc->root->d_sb); in zonefs_reconfigure()
1381 sbi->s_mount_opts = ctx->s_mount_opts; in zonefs_reconfigure()
1402 return -ENOMEM; in zonefs_init_fs_context()
1403 ctx->s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO; in zonefs_init_fs_context()
1404 fc->ops = &zonefs_context_ops; in zonefs_init_fs_context()
1405 fc->fs_private = ctx; in zonefs_init_fs_context()
1429 return -ENOMEM; in zonefs_init_inodecache()