Lines Matching +full:a +full:- +full:z
1 // SPDX-License-Identifier: GPL-2.0
31 * Get the name of a zone group directory.
50 struct zonefs_zone *z) in zonefs_account_active() argument
54 if (zonefs_zone_is_cnv(z)) in zonefs_account_active()
61 if (z->z_flags & (ZONEFS_ZONE_OFFLINE | ZONEFS_ZONE_READONLY)) in zonefs_account_active()
68 if ((z->z_flags & ZONEFS_ZONE_OPEN) || in zonefs_account_active()
69 (z->z_wpoffset > 0 && z->z_wpoffset < z->z_capacity)) { in zonefs_account_active()
70 if (!(z->z_flags & ZONEFS_ZONE_ACTIVE)) { in zonefs_account_active()
71 z->z_flags |= ZONEFS_ZONE_ACTIVE; in zonefs_account_active()
72 atomic_inc(&sbi->s_active_seq_files); in zonefs_account_active()
79 if (z->z_flags & ZONEFS_ZONE_ACTIVE) { in zonefs_account_active()
80 z->z_flags &= ~ZONEFS_ZONE_ACTIVE; in zonefs_account_active()
81 atomic_dec(&sbi->s_active_seq_files); in zonefs_account_active()
86 * Manage the active zone count. Called with zi->i_truncate_mutex held.
90 lockdep_assert_held(&ZONEFS_I(inode)->i_truncate_mutex); in zonefs_inode_account_active()
92 return zonefs_account_active(inode->i_sb, zonefs_inode_zone(inode)); in zonefs_inode_account_active()
96 * Execute a zone management operation.
99 struct zonefs_zone *z, enum req_op op) in zonefs_zone_mgmt() argument
111 if (op == REQ_OP_ZONE_CLOSE && !z->z_wpoffset) in zonefs_zone_mgmt()
114 trace_zonefs_zone_mgmt(sb, z, op); in zonefs_zone_mgmt()
115 ret = blkdev_zone_mgmt(sb->s_bdev, op, z->z_sector, in zonefs_zone_mgmt()
116 z->z_size >> SECTOR_SHIFT, GFP_NOFS); in zonefs_zone_mgmt()
120 blk_op_str(op), z->z_sector, ret); in zonefs_zone_mgmt()
129 lockdep_assert_held(&ZONEFS_I(inode)->i_truncate_mutex); in zonefs_inode_zone_mgmt()
131 return zonefs_zone_mgmt(inode->i_sb, zonefs_inode_zone(inode), op); in zonefs_inode_zone_mgmt()
136 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_i_size_write() local
141 * A full zone is no longer open/active and does not need in zonefs_i_size_write()
144 if (isize >= z->z_capacity) { in zonefs_i_size_write()
145 struct zonefs_sb_info *sbi = ZONEFS_SB(inode->i_sb); in zonefs_i_size_write()
147 if (z->z_flags & ZONEFS_ZONE_ACTIVE) in zonefs_i_size_write()
148 atomic_dec(&sbi->s_active_seq_files); in zonefs_i_size_write()
149 z->z_flags &= ~(ZONEFS_ZONE_OPEN | ZONEFS_ZONE_ACTIVE); in zonefs_i_size_write()
155 struct super_block *sb = inode->i_sb; in zonefs_update_stats()
163 spin_lock(&sbi->s_lock); in zonefs_update_stats()
170 nr_blocks = (old_isize - new_isize) >> sb->s_blocksize_bits; in zonefs_update_stats()
171 if (sbi->s_used_blocks > nr_blocks) in zonefs_update_stats()
172 sbi->s_used_blocks -= nr_blocks; in zonefs_update_stats()
174 sbi->s_used_blocks = 0; in zonefs_update_stats()
176 sbi->s_used_blocks += in zonefs_update_stats()
177 (new_isize - old_isize) >> sb->s_blocksize_bits; in zonefs_update_stats()
178 if (sbi->s_used_blocks > sbi->s_blocks) in zonefs_update_stats()
179 sbi->s_used_blocks = sbi->s_blocks; in zonefs_update_stats()
182 spin_unlock(&sbi->s_lock); in zonefs_update_stats()
186 * Check a zone condition. Return the amount of written (and still readable)
190 struct zonefs_zone *z, in zonefs_check_zone_condition() argument
193 switch (zone->cond) { in zonefs_check_zone_condition()
196 z->z_sector); in zonefs_check_zone_condition()
197 z->z_flags |= ZONEFS_ZONE_OFFLINE; in zonefs_check_zone_condition()
201 * The write pointer of read-only zones is invalid, so we cannot in zonefs_check_zone_condition()
204 * (wpoffset == 0) on mount. For a runtime error, this keeps in zonefs_check_zone_condition()
208 zonefs_warn(sb, "Zone %llu: read-only zone\n", in zonefs_check_zone_condition()
209 z->z_sector); in zonefs_check_zone_condition()
210 z->z_flags |= ZONEFS_ZONE_READONLY; in zonefs_check_zone_condition()
211 if (zonefs_zone_is_cnv(z)) in zonefs_check_zone_condition()
212 return z->z_capacity; in zonefs_check_zone_condition()
213 return z->z_wpoffset; in zonefs_check_zone_condition()
216 return z->z_capacity; in zonefs_check_zone_condition()
218 if (zonefs_zone_is_cnv(z)) in zonefs_check_zone_condition()
219 return z->z_capacity; in zonefs_check_zone_condition()
220 return (zone->wp - zone->start) << SECTOR_SHIFT; in zonefs_check_zone_condition()
225 * Check a zone condition and adjust its inode access permissions for
230 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_inode_update_mode() local
232 if (z->z_flags & ZONEFS_ZONE_OFFLINE) { in zonefs_inode_update_mode()
234 inode->i_flags |= S_IMMUTABLE; in zonefs_inode_update_mode()
235 inode->i_mode &= ~0777; in zonefs_inode_update_mode()
236 } else if (z->z_flags & ZONEFS_ZONE_READONLY) { in zonefs_inode_update_mode()
238 inode->i_flags |= S_IMMUTABLE; in zonefs_inode_update_mode()
239 if (z->z_flags & ZONEFS_ZONE_INIT_MODE) in zonefs_inode_update_mode()
240 inode->i_mode &= ~0777; in zonefs_inode_update_mode()
242 inode->i_mode &= ~0222; in zonefs_inode_update_mode()
245 z->z_flags &= ~ZONEFS_ZONE_INIT_MODE; in zonefs_inode_update_mode()
246 z->z_mode = inode->i_mode; in zonefs_inode_update_mode()
252 struct blk_zone *z = data; in zonefs_io_error_cb() local
254 *z = *zone; in zonefs_io_error_cb()
261 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_handle_io_error() local
262 struct super_block *sb = inode->i_sb; in zonefs_handle_io_error()
268 * read-only), read errors are simply signaled to the IO issuer as long in zonefs_handle_io_error()
272 data_size = zonefs_check_zone_condition(sb, z, zone); in zonefs_handle_io_error()
274 if (!(z->z_flags & (ZONEFS_ZONE_READONLY | ZONEFS_ZONE_OFFLINE)) && in zonefs_handle_io_error()
279 * At this point, we detected either a bad zone or an inconsistency in zonefs_handle_io_error()
281 * For the latter case, the cause may be a write IO error or an external in zonefs_handle_io_error()
284 * a write operation partially failed and data was writen at the end in zonefs_handle_io_error()
285 * of the file. This can happen in the case of a large direct IO in zonefs_handle_io_error()
288 * this can happen with a deferred write error with the use of the in zonefs_handle_io_error()
290 * completions. Other possibilities are (a) an external corruption, in zonefs_handle_io_error()
292 * has a serious problem (e.g. firmware bug). in zonefs_handle_io_error()
300 inode->i_ino, isize, data_size); in zonefs_handle_io_error()
304 * errors=zone-ro and errors=zone-offline result in changing the in zonefs_handle_io_error()
305 * zone condition to read-only and offline respectively, as if the in zonefs_handle_io_error()
308 if ((z->z_flags & ZONEFS_ZONE_OFFLINE) || in zonefs_handle_io_error()
309 (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZOL)) { in zonefs_handle_io_error()
311 inode->i_ino); in zonefs_handle_io_error()
312 if (!(z->z_flags & ZONEFS_ZONE_OFFLINE)) in zonefs_handle_io_error()
313 z->z_flags |= ZONEFS_ZONE_OFFLINE; in zonefs_handle_io_error()
316 } else if ((z->z_flags & ZONEFS_ZONE_READONLY) || in zonefs_handle_io_error()
317 (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZRO)) { in zonefs_handle_io_error()
319 inode->i_ino); in zonefs_handle_io_error()
320 if (!(z->z_flags & ZONEFS_ZONE_READONLY)) in zonefs_handle_io_error()
321 z->z_flags |= ZONEFS_ZONE_READONLY; in zonefs_handle_io_error()
324 } else if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO && in zonefs_handle_io_error()
331 * If the filesystem is mounted with the explicit-open mount option, we in zonefs_handle_io_error()
333 * the read-only or offline condition, to avoid attempting an explicit in zonefs_handle_io_error()
336 if ((sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) && in zonefs_handle_io_error()
337 (z->z_flags & (ZONEFS_ZONE_READONLY | ZONEFS_ZONE_OFFLINE))) in zonefs_handle_io_error()
338 z->z_flags &= ~ZONEFS_ZONE_OPEN; in zonefs_handle_io_error()
341 * If error=remount-ro was specified, any error result in remounting in zonefs_handle_io_error()
342 * the volume as read-only. in zonefs_handle_io_error()
344 if ((sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO) && !sb_rdonly(sb)) { in zonefs_handle_io_error()
345 zonefs_warn(sb, "remounting filesystem read-only\n"); in zonefs_handle_io_error()
346 sb->s_flags |= SB_RDONLY; in zonefs_handle_io_error()
355 z->z_wpoffset = data_size; in zonefs_handle_io_error()
360 * When an file IO error occurs, check the file zone to see if there is a change
361 * in the zone condition (e.g. offline or read-only). For a failed write to a
368 struct zonefs_zone *z = zonefs_inode_zone(inode); in __zonefs_io_error() local
369 struct super_block *sb = inode->i_sb; in __zonefs_io_error()
375 * Conventional zone have no write pointer and cannot become read-only in __zonefs_io_error()
376 * or offline. So simply fake a report for a single or aggregated zone in __zonefs_io_error()
380 if (!zonefs_zone_is_seq(z)) { in __zonefs_io_error()
381 zone.start = z->z_sector; in __zonefs_io_error()
382 zone.len = z->z_size >> SECTOR_SHIFT; in __zonefs_io_error()
391 * Memory allocations in blkdev_report_zones() can trigger a memory in __zonefs_io_error()
392 * reclaim which may in turn cause a recursion into zonefs as well as in __zonefs_io_error()
394 * end up in a deadlock on the inode truncate mutex, while the latter in __zonefs_io_error()
399 ret = blkdev_report_zones(sb->s_bdev, z->z_sector, 1, in __zonefs_io_error()
405 inode->i_ino, ret); in __zonefs_io_error()
406 zonefs_warn(sb, "remounting filesystem read-only\n"); in __zonefs_io_error()
407 sb->s_flags |= SB_RDONLY; in __zonefs_io_error()
425 inode_init_once(&zi->i_vnode); in zonefs_alloc_inode()
426 mutex_init(&zi->i_truncate_mutex); in zonefs_alloc_inode()
427 zi->i_wr_refcnt = 0; in zonefs_alloc_inode()
429 return &zi->i_vnode; in zonefs_alloc_inode()
442 struct super_block *sb = dentry->d_sb; in zonefs_statfs()
446 buf->f_type = ZONEFS_MAGIC; in zonefs_statfs()
447 buf->f_bsize = sb->s_blocksize; in zonefs_statfs()
448 buf->f_namelen = ZONEFS_NAME_MAX; in zonefs_statfs()
450 spin_lock(&sbi->s_lock); in zonefs_statfs()
452 buf->f_blocks = sbi->s_blocks; in zonefs_statfs()
453 if (WARN_ON(sbi->s_used_blocks > sbi->s_blocks)) in zonefs_statfs()
454 buf->f_bfree = 0; in zonefs_statfs()
456 buf->f_bfree = buf->f_blocks - sbi->s_used_blocks; in zonefs_statfs()
457 buf->f_bavail = buf->f_bfree; in zonefs_statfs()
460 if (sbi->s_zgroup[t].g_nr_zones) in zonefs_statfs()
461 buf->f_files += sbi->s_zgroup[t].g_nr_zones + 1; in zonefs_statfs()
463 buf->f_ffree = 0; in zonefs_statfs()
465 spin_unlock(&sbi->s_lock); in zonefs_statfs()
467 buf->f_fsid = uuid_to_fsid(sbi->s_uuid.b); in zonefs_statfs()
478 { Opt_errors_ro, "errors=remount-ro"},
479 { Opt_errors_zro, "errors=zone-ro"},
480 { Opt_errors_zol, "errors=zone-offline"},
482 { Opt_explicit_open, "explicit-open" },
504 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK; in zonefs_parse_options()
505 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_RO; in zonefs_parse_options()
508 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK; in zonefs_parse_options()
509 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZRO; in zonefs_parse_options()
512 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK; in zonefs_parse_options()
513 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZOL; in zonefs_parse_options()
516 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK; in zonefs_parse_options()
517 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_REPAIR; in zonefs_parse_options()
520 sbi->s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN; in zonefs_parse_options()
523 return -EINVAL; in zonefs_parse_options()
532 struct zonefs_sb_info *sbi = ZONEFS_SB(root->d_sb); in zonefs_show_options()
534 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO) in zonefs_show_options()
535 seq_puts(seq, ",errors=remount-ro"); in zonefs_show_options()
536 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZRO) in zonefs_show_options()
537 seq_puts(seq, ",errors=zone-ro"); in zonefs_show_options()
538 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_ZOL) in zonefs_show_options()
539 seq_puts(seq, ",errors=zone-offline"); in zonefs_show_options()
540 if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_REPAIR) in zonefs_show_options()
560 return -EPERM; in zonefs_inode_setattr()
568 * allow setting any write attributes on the sub-directories grouping in zonefs_inode_setattr()
571 if ((iattr->ia_valid & ATTR_MODE) && S_ISDIR(inode->i_mode) && in zonefs_inode_setattr()
572 (iattr->ia_mode & 0222)) in zonefs_inode_setattr()
573 return -EPERM; in zonefs_inode_setattr()
575 if (((iattr->ia_valid & ATTR_UID) && in zonefs_inode_setattr()
576 !uid_eq(iattr->ia_uid, inode->i_uid)) || in zonefs_inode_setattr()
577 ((iattr->ia_valid & ATTR_GID) && in zonefs_inode_setattr()
578 !gid_eq(iattr->ia_gid, inode->i_gid))) { in zonefs_inode_setattr()
584 if (iattr->ia_valid & ATTR_SIZE) { in zonefs_inode_setattr()
585 ret = zonefs_file_truncate(inode, iattr->ia_size); in zonefs_inode_setattr()
592 if (S_ISREG(inode->i_mode)) { in zonefs_inode_setattr()
593 struct zonefs_zone *z = zonefs_inode_zone(inode); in zonefs_inode_setattr() local
595 z->z_mode = inode->i_mode; in zonefs_inode_setattr()
596 z->z_uid = inode->i_uid; in zonefs_inode_setattr()
597 z->z_gid = inode->i_gid; in zonefs_inode_setattr()
609 const char *name = fname->name; in zonefs_fname_to_fno()
610 unsigned int len = fname->len; in zonefs_fname_to_fno()
617 * File names are always a base-10 number string without any in zonefs_fname_to_fno()
621 return -ENOENT; in zonefs_fname_to_fno()
624 return -ENOENT; in zonefs_fname_to_fno()
627 return c - '0'; in zonefs_fname_to_fno()
629 for (i = 0, rname = name + len - 1; i < len; i++, rname--) { in zonefs_fname_to_fno()
632 return -ENOENT; in zonefs_fname_to_fno()
633 fno += (c - '0') * shift; in zonefs_fname_to_fno()
643 struct zonefs_zone_group *zgroup = dir->i_private; in zonefs_get_file_inode()
644 struct super_block *sb = dir->i_sb; in zonefs_get_file_inode()
646 struct zonefs_zone *z; in zonefs_get_file_inode() local
652 fno = zonefs_fname_to_fno(&dentry->d_name); in zonefs_get_file_inode()
656 if (!zgroup->g_nr_zones || fno >= zgroup->g_nr_zones) in zonefs_get_file_inode()
657 return ERR_PTR(-ENOENT); in zonefs_get_file_inode()
659 z = &zgroup->g_zones[fno]; in zonefs_get_file_inode()
660 ino = z->z_sector >> sbi->s_zone_sectors_shift; in zonefs_get_file_inode()
663 return ERR_PTR(-ENOMEM); in zonefs_get_file_inode()
664 if (!(inode->i_state & I_NEW)) { in zonefs_get_file_inode()
665 WARN_ON_ONCE(inode->i_private != z); in zonefs_get_file_inode()
669 inode->i_ino = ino; in zonefs_get_file_inode()
670 inode->i_mode = z->z_mode; in zonefs_get_file_inode()
671 inode->i_mtime = inode->i_atime = inode_set_ctime_to_ts(inode, in zonefs_get_file_inode()
673 inode->i_uid = z->z_uid; in zonefs_get_file_inode()
674 inode->i_gid = z->z_gid; in zonefs_get_file_inode()
675 inode->i_size = z->z_wpoffset; in zonefs_get_file_inode()
676 inode->i_blocks = z->z_capacity >> SECTOR_SHIFT; in zonefs_get_file_inode()
677 inode->i_private = z; in zonefs_get_file_inode()
679 inode->i_op = &zonefs_file_inode_operations; in zonefs_get_file_inode()
680 inode->i_fop = &zonefs_file_operations; in zonefs_get_file_inode()
681 inode->i_mapping->a_ops = &zonefs_file_aops; in zonefs_get_file_inode()
694 struct inode *root = d_inode(sb->s_root); in zonefs_get_zgroup_inode()
697 ino_t ino = bdev_nr_zones(sb->s_bdev) + ztype + 1; in zonefs_get_zgroup_inode()
701 return ERR_PTR(-ENOMEM); in zonefs_get_zgroup_inode()
702 if (!(inode->i_state & I_NEW)) in zonefs_get_zgroup_inode()
705 inode->i_ino = ino; in zonefs_get_zgroup_inode()
707 inode->i_size = sbi->s_zgroup[ztype].g_nr_zones; in zonefs_get_zgroup_inode()
708 inode->i_mtime = inode->i_atime = inode_set_ctime_to_ts(inode, in zonefs_get_zgroup_inode()
710 inode->i_private = &sbi->s_zgroup[ztype]; in zonefs_get_zgroup_inode()
713 inode->i_op = &zonefs_dir_inode_operations; in zonefs_get_zgroup_inode()
714 inode->i_fop = &zonefs_dir_operations; in zonefs_get_zgroup_inode()
725 struct super_block *sb = dir->i_sb; in zonefs_get_dir_inode()
727 const char *name = dentry->d_name.name; in zonefs_get_dir_inode()
734 if (dentry->d_name.len != 3) in zonefs_get_dir_inode()
735 return ERR_PTR(-ENOENT); in zonefs_get_dir_inode()
738 if (sbi->s_zgroup[ztype].g_nr_zones && in zonefs_get_dir_inode()
743 return ERR_PTR(-ENOENT); in zonefs_get_dir_inode()
753 if (dentry->d_name.len > ZONEFS_NAME_MAX) in zonefs_lookup()
754 return ERR_PTR(-ENAMETOOLONG); in zonefs_lookup()
756 if (dir == d_inode(dir->i_sb->s_root)) in zonefs_lookup()
769 struct super_block *sb = inode->i_sb; in zonefs_readdir_root()
772 ino_t base_ino = bdev_nr_zones(sb->s_bdev) + 1; in zonefs_readdir_root()
774 if (ctx->pos >= inode->i_size) in zonefs_readdir_root()
780 if (ctx->pos == 2) { in zonefs_readdir_root()
781 if (!sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones) in zonefs_readdir_root()
787 ctx->pos++; in zonefs_readdir_root()
790 if (ctx->pos == 3 && ztype != ZONEFS_ZTYPE_SEQ) { in zonefs_readdir_root()
795 ctx->pos++; in zonefs_readdir_root()
805 struct zonefs_zone_group *zgroup = inode->i_private; in zonefs_readdir_zgroup()
806 struct super_block *sb = inode->i_sb; in zonefs_readdir_zgroup()
808 struct zonefs_zone *z; in zonefs_readdir_zgroup() local
819 if (ctx->pos >= inode->i_size + 2) in zonefs_readdir_zgroup()
827 return -ENOMEM; in zonefs_readdir_zgroup()
829 for (f = ctx->pos - 2; f < zgroup->g_nr_zones; f++) { in zonefs_readdir_zgroup()
830 z = &zgroup->g_zones[f]; in zonefs_readdir_zgroup()
831 ino = z->z_sector >> sbi->s_zone_sectors_shift; in zonefs_readdir_zgroup()
832 fname_len = snprintf(fname, ZONEFS_NAME_MAX - 1, "%u", f); in zonefs_readdir_zgroup()
835 ctx->pos++; in zonefs_readdir_zgroup()
847 if (inode == d_inode(inode->i_sb->s_root)) in zonefs_readdir()
875 struct super_block *sb = zd->sb; in zonefs_get_zone_info_cb()
880 * and not exposed as a file. in zonefs_get_zone_info_cb()
891 switch (zone->type) { in zonefs_get_zone_info_cb()
893 if (sbi->s_features & ZONEFS_F_AGGRCNV) { in zonefs_get_zone_info_cb()
895 if (!(sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones) || in zonefs_get_zone_info_cb()
896 zone->start != zd->cnv_zone_start) in zonefs_get_zone_info_cb()
897 sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones++; in zonefs_get_zone_info_cb()
898 zd->cnv_zone_start = zone->start + zone->len; in zonefs_get_zone_info_cb()
901 sbi->s_zgroup[ZONEFS_ZTYPE_CNV].g_nr_zones++; in zonefs_get_zone_info_cb()
906 sbi->s_zgroup[ZONEFS_ZTYPE_SEQ].g_nr_zones++; in zonefs_get_zone_info_cb()
909 zonefs_err(zd->sb, "Unsupported zone type 0x%x\n", in zonefs_get_zone_info_cb()
910 zone->type); in zonefs_get_zone_info_cb()
911 return -EIO; in zonefs_get_zone_info_cb()
914 memcpy(&zd->zones[idx], zone, sizeof(struct blk_zone)); in zonefs_get_zone_info_cb()
921 struct block_device *bdev = zd->sb->s_bdev; in zonefs_get_zone_info()
924 zd->zones = kvcalloc(bdev_nr_zones(bdev), sizeof(struct blk_zone), in zonefs_get_zone_info()
926 if (!zd->zones) in zonefs_get_zone_info()
927 return -ENOMEM; in zonefs_get_zone_info()
933 zonefs_err(zd->sb, "Zone report failed %d\n", ret); in zonefs_get_zone_info()
938 zonefs_err(zd->sb, "Invalid zone report (%d/%u zones)\n", in zonefs_get_zone_info()
940 return -EIO; in zonefs_get_zone_info()
948 kvfree(zd->zones); in zonefs_free_zone_info()
952 * Create a zone group and populate it with zone files.
959 struct zonefs_zone_group *zgroup = &sbi->s_zgroup[ztype]; in zonefs_init_zgroup()
961 struct zonefs_zone *z; in zonefs_init_zgroup() local
966 if (!zgroup->g_nr_zones) in zonefs_init_zgroup()
969 zgroup->g_zones = kvcalloc(zgroup->g_nr_zones, in zonefs_init_zgroup()
971 if (!zgroup->g_zones) in zonefs_init_zgroup()
972 return -ENOMEM; in zonefs_init_zgroup()
977 * and is not use to back a file. in zonefs_init_zgroup()
979 end = zd->zones + bdev_nr_zones(sb->s_bdev); in zonefs_init_zgroup()
980 for (zone = &zd->zones[1]; zone < end; zone = next) { in zonefs_init_zgroup()
986 if (WARN_ON_ONCE(n >= zgroup->g_nr_zones)) in zonefs_init_zgroup()
987 return -EINVAL; in zonefs_init_zgroup()
993 * aggregated together. If one offline or read-only zone is in zonefs_init_zgroup()
998 (sbi->s_features & ZONEFS_F_AGGRCNV)) { in zonefs_init_zgroup()
1002 zone->len += next->len; in zonefs_init_zgroup()
1003 zone->capacity += next->capacity; in zonefs_init_zgroup()
1004 if (next->cond == BLK_ZONE_COND_READONLY && in zonefs_init_zgroup()
1005 zone->cond != BLK_ZONE_COND_OFFLINE) in zonefs_init_zgroup()
1006 zone->cond = BLK_ZONE_COND_READONLY; in zonefs_init_zgroup()
1007 else if (next->cond == BLK_ZONE_COND_OFFLINE) in zonefs_init_zgroup()
1008 zone->cond = BLK_ZONE_COND_OFFLINE; in zonefs_init_zgroup()
1012 z = &zgroup->g_zones[n]; in zonefs_init_zgroup()
1014 z->z_flags |= ZONEFS_ZONE_CNV; in zonefs_init_zgroup()
1015 z->z_sector = zone->start; in zonefs_init_zgroup()
1016 z->z_size = zone->len << SECTOR_SHIFT; in zonefs_init_zgroup()
1017 if (z->z_size > bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT && in zonefs_init_zgroup()
1018 !(sbi->s_features & ZONEFS_F_AGGRCNV)) { in zonefs_init_zgroup()
1021 z->z_size, in zonefs_init_zgroup()
1022 bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT); in zonefs_init_zgroup()
1023 return -EINVAL; in zonefs_init_zgroup()
1026 z->z_capacity = min_t(loff_t, MAX_LFS_FILESIZE, in zonefs_init_zgroup()
1027 zone->capacity << SECTOR_SHIFT); in zonefs_init_zgroup()
1028 z->z_wpoffset = zonefs_check_zone_condition(sb, z, zone); in zonefs_init_zgroup()
1030 z->z_mode = S_IFREG | sbi->s_perm; in zonefs_init_zgroup()
1031 z->z_uid = sbi->s_uid; in zonefs_init_zgroup()
1032 z->z_gid = sbi->s_gid; in zonefs_init_zgroup()
1039 z->z_flags |= ZONEFS_ZONE_INIT_MODE; in zonefs_init_zgroup()
1041 sb->s_maxbytes = max(z->z_capacity, sb->s_maxbytes); in zonefs_init_zgroup()
1042 sbi->s_blocks += z->z_capacity >> sb->s_blocksize_bits; in zonefs_init_zgroup()
1043 sbi->s_used_blocks += z->z_wpoffset >> sb->s_blocksize_bits; in zonefs_init_zgroup()
1052 (zone->cond == BLK_ZONE_COND_IMP_OPEN || in zonefs_init_zgroup()
1053 zone->cond == BLK_ZONE_COND_EXP_OPEN)) { in zonefs_init_zgroup()
1054 ret = zonefs_zone_mgmt(sb, z, REQ_OP_ZONE_CLOSE); in zonefs_init_zgroup()
1059 zonefs_account_active(sb, z); in zonefs_init_zgroup()
1064 if (WARN_ON_ONCE(n != zgroup->g_nr_zones)) in zonefs_init_zgroup()
1065 return -EINVAL; in zonefs_init_zgroup()
1069 zgroup->g_nr_zones, in zonefs_init_zgroup()
1070 zgroup->g_nr_zones > 1 ? "s" : ""); in zonefs_init_zgroup()
1084 kvfree(sbi->s_zgroup[ztype].g_zones); in zonefs_free_zgroups()
1085 sbi->s_zgroup[ztype].g_zones = NULL; in zonefs_free_zgroups()
1090 * Create a zone group and populate it with zone files.
1139 return -ENOMEM; in zonefs_read_super()
1141 bio_init(&bio, sb->s_bdev, &bio_vec, 1, REQ_OP_READ); in zonefs_read_super()
1151 ret = -EINVAL; in zonefs_read_super()
1152 if (le32_to_cpu(super->s_magic) != ZONEFS_MAGIC) in zonefs_read_super()
1155 stored_crc = le32_to_cpu(super->s_crc); in zonefs_read_super()
1156 super->s_crc = 0; in zonefs_read_super()
1164 sbi->s_features = le64_to_cpu(super->s_features); in zonefs_read_super()
1165 if (sbi->s_features & ~ZONEFS_F_DEFINED_FEATURES) { in zonefs_read_super()
1167 sbi->s_features); in zonefs_read_super()
1171 if (sbi->s_features & ZONEFS_F_UID) { in zonefs_read_super()
1172 sbi->s_uid = make_kuid(current_user_ns(), in zonefs_read_super()
1173 le32_to_cpu(super->s_uid)); in zonefs_read_super()
1174 if (!uid_valid(sbi->s_uid)) { in zonefs_read_super()
1180 if (sbi->s_features & ZONEFS_F_GID) { in zonefs_read_super()
1181 sbi->s_gid = make_kgid(current_user_ns(), in zonefs_read_super()
1182 le32_to_cpu(super->s_gid)); in zonefs_read_super()
1183 if (!gid_valid(sbi->s_gid)) { in zonefs_read_super()
1189 if (sbi->s_features & ZONEFS_F_PERM) in zonefs_read_super()
1190 sbi->s_perm = le32_to_cpu(super->s_perm); in zonefs_read_super()
1192 if (memchr_inv(super->s_reserved, 0, sizeof(super->s_reserved))) { in zonefs_read_super()
1197 import_uuid(&sbi->s_uuid, super->s_uuid); in zonefs_read_super()
1221 if (!sbi->s_zgroup[ztype].g_nr_zones) in zonefs_get_zgroup_inodes()
1228 sbi->s_zgroup[ztype].g_inode = dir_inode; in zonefs_get_zgroup_inodes()
1243 if (sbi->s_zgroup[ztype].g_inode) { in zonefs_release_zgroup_inodes()
1244 iput(sbi->s_zgroup[ztype].g_inode); in zonefs_release_zgroup_inodes()
1245 sbi->s_zgroup[ztype].g_inode = NULL; in zonefs_release_zgroup_inodes()
1252 * sub-directories and files according to the device zone configuration and
1262 if (!bdev_is_zoned(sb->s_bdev)) { in zonefs_fill_super()
1263 zonefs_err(sb, "Not a zoned block device\n"); in zonefs_fill_super()
1264 return -EINVAL; in zonefs_fill_super()
1270 * ZONEFS_F_AGGRCNV which increases the maximum file size of a file in zonefs_fill_super()
1275 return -ENOMEM; in zonefs_fill_super()
1277 spin_lock_init(&sbi->s_lock); in zonefs_fill_super()
1278 sb->s_fs_info = sbi; in zonefs_fill_super()
1279 sb->s_magic = ZONEFS_MAGIC; in zonefs_fill_super()
1280 sb->s_maxbytes = 0; in zonefs_fill_super()
1281 sb->s_op = &zonefs_sops; in zonefs_fill_super()
1282 sb->s_time_gran = 1; in zonefs_fill_super()
1289 sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev)); in zonefs_fill_super()
1290 sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev)); in zonefs_fill_super()
1291 sbi->s_uid = GLOBAL_ROOT_UID; in zonefs_fill_super()
1292 sbi->s_gid = GLOBAL_ROOT_GID; in zonefs_fill_super()
1293 sbi->s_perm = 0640; in zonefs_fill_super()
1294 sbi->s_mount_opts = ZONEFS_MNTOPT_ERRORS_RO; in zonefs_fill_super()
1296 atomic_set(&sbi->s_wro_seq_files, 0); in zonefs_fill_super()
1297 sbi->s_max_wro_seq_files = bdev_max_open_zones(sb->s_bdev); in zonefs_fill_super()
1298 atomic_set(&sbi->s_active_seq_files, 0); in zonefs_fill_super()
1299 sbi->s_max_active_seq_files = bdev_max_active_zones(sb->s_bdev); in zonefs_fill_super()
1309 zonefs_info(sb, "Mounting %u zones", bdev_nr_zones(sb->s_bdev)); in zonefs_fill_super()
1311 if (!sbi->s_max_wro_seq_files && in zonefs_fill_super()
1312 !sbi->s_max_active_seq_files && in zonefs_fill_super()
1313 sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { in zonefs_fill_super()
1316 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN; in zonefs_fill_super()
1325 ret = -ENOMEM; in zonefs_fill_super()
1330 inode->i_ino = bdev_nr_zones(sb->s_bdev); in zonefs_fill_super()
1331 inode->i_mode = S_IFDIR | 0555; in zonefs_fill_super()
1332 inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode); in zonefs_fill_super()
1333 inode->i_op = &zonefs_dir_inode_operations; in zonefs_fill_super()
1334 inode->i_fop = &zonefs_dir_operations; in zonefs_fill_super()
1335 inode->i_size = 2; in zonefs_fill_super()
1338 if (sbi->s_zgroup[ztype].g_nr_zones) { in zonefs_fill_super()
1340 inode->i_size++; in zonefs_fill_super()
1344 sb->s_root = d_make_root(inode); in zonefs_fill_super()
1345 if (!sb->s_root) in zonefs_fill_super()
1349 * Take a reference on the zone groups directory inodes in zonefs_fill_super()
1407 return -ENOMEM; in zonefs_init_inodecache()