From d47a71f7a894a193957fe7771d43c5767979c117 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Fri, 1 Nov 2024 10:39:13 +0800 Subject: [PATCH] LU-18360 zfs-osd: za_name flexible array zfs-2.3 commit 3cf2bfa57008af7f0690f73491d7f9b4ac4ed65a Allocate zap_attribute_t from kmem instead of stack za_name maximum size increased to ZAP_MAXNAMELEN_NEW Ensure zap_attribute_t.za_name space is available and zap_attribute_t.za_name_len now needs to be initialized to the allocated space of MAXNAMELEN. Also mkfs should disable longname support as it would break MAX_NAME interop. HPE-bug-id: LUS-12561 Test-Parameters: fstype=zfs Signed-off-by: Shaun Tancheff Change-Id: I6c48c66a42a36ea6816b37ffce7e17f45eed3dbf Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56656 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin Reviewed-by: James Simmons --- lustre.spec.in | 2 +- lustre/osd-zfs/osd_handler.c | 12 ++++++++---- lustre/osd-zfs/osd_index.c | 7 +++++++ lustre/osd-zfs/osd_internal.h | 12 ++++++++++++ lustre/utils/libmount_utils_zfs.c | 9 ++++++++- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lustre.spec.in b/lustre.spec.in index 793058c..eb3a157 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -387,7 +387,7 @@ Provides: %{name}-osd-mount = %{version} Obsoletes: lustre-osd-mount < %{version} %if 0%{confzfsdobjpath} != 0 %if 0%{?suse_version} >= 1500 || 0%{?rhel} >= 8 || 0%{?fedora} >= 34 -BuildRequires: (libzfs-devel or libzfs4-devel or libzfs5-devel) +BuildRequires: (libzfs-devel or libzfs4-devel or libzfs5-devel or libzfs6-devel) %else # 'or' is not available, Use: --define 'zfs 5' or 'zfs 4' BuildRequires: libzfs%{?zfs}-devel diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 30063cc..9cf26ee 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -742,10 +742,14 @@ static void *osd_key_init(const struct lu_context *ctx, struct osd_thread_info *info; OBD_ALLOC_PTR(info); - if (info != NULL) - info->oti_env = container_of(ctx, struct lu_env, le_ctx); - else - info = ERR_PTR(-ENOMEM); + if (!info) + return ERR_PTR(-ENOMEM); + + info->oti_env = container_of(ctx, struct lu_env, le_ctx); +#ifdef ZAP_MAXNAMELEN_NEW + info->oti_za.za_name_len = MAXNAMELEN; + info->oti_za2.za_name_len = MAXNAMELEN; +#endif return info; } diff --git a/lustre/osd-zfs/osd_index.c b/lustre/osd-zfs/osd_index.c index a3ed468..53ee420 100644 --- a/lustre/osd-zfs/osd_index.c +++ b/lustre/osd-zfs/osd_index.c @@ -141,6 +141,9 @@ static struct dt_it *osd_index_it_init(const struct lu_env *env, it->ozi_obj = obj; it->ozi_reset = 1; +#ifdef ZAP_MAXNAMELEN_NEW + it->ozi_za.za_name_len = MAXNAMELEN; +#endif lu_object_get(lo); RETURN((struct dt_it *)it); @@ -1323,7 +1326,11 @@ static int osd_dir_it_next(const struct lu_env *env, struct dt_it *di) ENTRY; /* temp. storage should be enough for any key supported by ZFS */ +#ifdef ZAP_MAXNAMELEN_NEW + LASSERT(za->za_name_len <= sizeof(it->ozi_name)); +#else BUILD_BUG_ON(sizeof(za->za_name) > sizeof(it->ozi_name)); +#endif /* * the first ->next() moves the cursor to . diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index 28b7a9a..fbbe0ee 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -146,6 +146,10 @@ struct osd_zap_it { enum osd_zap_pos ozi_pos; struct luz_direntry ozi_zde; zap_attribute_t ozi_za; +#ifdef ZAP_MAXNAMELEN_NEW + /* flexible array: zap_attribute_t.za_name[], ensure space allocated */ + char ozi_za_name_buffer[MAXNAMELEN]; +#endif union { char ozi_name[MAXNAMELEN]; /* file name for dir */ __u64 ozi_key; /* binary key for index files */ @@ -238,7 +242,15 @@ struct osd_thread_info { struct lu_attr oti_la; struct osa_attr oti_osa; zap_attribute_t oti_za; +#ifdef ZAP_MAXNAMELEN_NEW + /* flexible array: zap_attribute_t.za_name[], ensure space allocated */ + char oti_za_name_buffer[MAXNAMELEN]; +#endif zap_attribute_t oti_za2; +#ifdef ZAP_MAXNAMELEN_NEW + /* flexible array: zap_attribute_t.za_name[], ensure space allocated */ + char oti_za2_name_buffer[MAXNAMELEN]; +#endif dmu_object_info_t oti_doi; struct luz_direntry oti_zde; diff --git a/lustre/utils/libmount_utils_zfs.c b/lustre/utils/libmount_utils_zfs.c index f6eb764..68a1c8d 100644 --- a/lustre/utils/libmount_utils_zfs.c +++ b/lustre/utils/libmount_utils_zfs.c @@ -636,6 +636,12 @@ static int zfs_create_vdev(struct mkfs_opts *mop, char *vdev) return ret; } +/* interop will break if we change MAX_NAME from 255 */ +#ifdef ZAP_MAXNAMELEN_NEW +#define ZFS_LONGNAME_FEATURE " -o feature@longname=disabled" +#else +#define ZFS_LONGNAME_FEATURE "" +#endif int zfs_make_lustre(struct mkfs_opts *mop) { @@ -713,7 +719,8 @@ int zfs_make_lustre(struct mkfs_opts *mop) memset(mkfs_cmd, 0, PATH_MAX); snprintf(mkfs_cmd, PATH_MAX, - "zpool create -f -O canmount=off %s", pool); + "zpool create%s -f -O canmount=off %s", + ZFS_LONGNAME_FEATURE, pool); /* Append the vdev config and create file vdevs as required */ while (*mop->mo_pool_vdevs != NULL) { -- 1.8.3.1