From 300ec82bacf985883195726ef6514695c45ef2ec Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Fri, 11 Feb 2022 12:11:28 -0600 Subject: [PATCH] EX-4015 lipe: handle trusted xattrs uniformly Add a wrapper (ldiskfs_trusted_xattr_get()) around ext2fs_attr_get() to do uniform error messages and error handling. Test-Parameters: trivial testlist=sanity-lipe-scan3 facet=mds1 Signed-off-by: John L. Hammond Change-Id: I5ad82a56b7729354364afa594b3d8d9ee83a4b7f Reviewed-on: https://review.whamcloud.com/46513 Tested-by: jenkins Tested-by: Maloo --- lipe/src/lipe_scan3/ls3_scan.c | 174 ++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 108 deletions(-) diff --git a/lipe/src/lipe_scan3/ls3_scan.c b/lipe/src/lipe_scan3/ls3_scan.c index 4794fc8..b4fc411 100644 --- a/lipe/src/lipe_scan3/ls3_scan.c +++ b/lipe/src/lipe_scan3/ls3_scan.c @@ -90,37 +90,54 @@ static bool xattr_name_not_found(long errcode) errcode == EXT2_ET_EA_NAME_NOT_FOUND_1462WC3; } -/* FIXME Wrap ext2fs_attr_get() and check xattr_name_not_found(). */ +static int ldiskfs_trusted_xattr_get(struct lipe_object *lo, + const char *name, + void *buf, size_t buf_size, + int *value_size) +{ + ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; + struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; + errcode_t rc; + + rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, + EXT2_ATTR_INDEX_TRUSTED, + name + strlen("trusted."), + buf, buf_size, value_size); + if (xattr_name_not_found(rc)) { + return -ENODATA; + } else if (rc) { + /* EXT2_ET_EA_TOO_BIG, what else? */ + + LS3_ERROR_OBJ(lo, "cannot get '%s' xattr: rc = %ld (%s)\n", + name, rc, error_message(rc)); + return -EINVAL; + } + + return 0; +} static int ldiskfs_read_attr_self_fid(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; - int size; - char buf[XATTR_SIZE_MAX]; struct lustre_mdt_attrs *lma; - errcode_t rc; + char buf[XATTR_SIZE_MAX]; + int size; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_SELF_FID) return 0; - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_LMA + strlen("trusted."), - buf, sizeof(buf), &size); - if (rc) { - LS3_DEBUG_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_LMA, rc); - return -ENODATA; - } + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LMA, buf, sizeof(buf), &size); + if (rc < 0) + return rc; lma = (struct lustre_mdt_attrs *)buf; fid_le_to_cpu(&loa->loa_self_fid, &lma->lma_self_fid); loa->loa_lma_compat = ext2fs_le32_to_cpu(lma->lma_compat); loa->loa_lma_incompat = ext2fs_le32_to_cpu(lma->lma_incompat); + loa->loa_attr_bits |= LS3_OBJECT_ATTR_SELF_FID; return 0; @@ -131,29 +148,22 @@ ldiskfs_read_attr_filter_fid(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; - int size; struct filter_fid *ff = &loa->loa_filter_fid; struct lu_fid pfid; - errcode_t rc; + int size; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_FILTER_FID) return 0; - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_FID + strlen("trusted."), - (char *)ff, sizeof(*ff), &size); - if (rc) { - LS3_DEBUG_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_FID, rc); - return -ENODATA; - } + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_FID, ff, sizeof(*ff), &size); + if (rc < 0) + return rc; fid_le_to_cpu(&pfid, &ff->ff_parent); ff->ff_parent = pfid; loa->loa_filter_fid_size = size; + loa->loa_attr_bits |= LS3_OBJECT_ATTR_FILTER_FID; return 0; @@ -164,7 +174,7 @@ ldiskfs_read_attr_file_fid(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - errcode_t rc; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_FILE_FID) return 0; @@ -198,10 +208,8 @@ ldiskfs_read_attr_links(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; int size; - errcode_t rc; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_LINKS) return 0; @@ -220,20 +228,13 @@ ldiskfs_read_attr_links(struct ls3_instance *li, if (loa->loa_lma_incompat & LMAI_ORPHAN) goto out_ok; - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_LINK + strlen("trusted."), - loa->loa_leh_buf, sizeof(loa->loa_leh_buf), - &size); - if (rc) { - LS3_DEBUG_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_LINK, (long)rc); - return -ENODATA; - } + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LINK, loa->loa_leh_buf, sizeof(loa->loa_leh_buf), &size); + if (rc < 0) + return rc; rc = lipe_object_attrs_set_links(loa, loa->loa_leh_buf, size); if (rc) { - LS3_ERROR_OBJ(lo, "cannot decode link xattr: rc = %ld\n", rc); + LS3_ERROR_OBJ(lo, "cannot decode link xattr: rc = %d\n", rc); return rc; } out_ok: @@ -343,7 +344,7 @@ static int ldiskfs_read_attr_xattrs(struct ls3_instance *li, rc = ext2fs_xattrs_open(fs, ino, &handle); if (rc) { LS3_ERROR_OBJ(lo, "cannot open xattrs: rc = %ld\n", rc); - return rc; + return -ENODATA; /* XXX? */ } rc = ext2fs_xattrs_read(handle); @@ -362,37 +363,28 @@ static int ldiskfs_read_attr_xattrs(struct ls3_instance *li, out_close: ext2fs_xattrs_close(&handle); - return rc; + return rc != 0 ? -ENODATA : 0; } static int ldiskfs_read_attr_lov(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; - int size; struct lov_user_md *lum = loa->loa_lum; struct llapi_layout *layout = NULL; - errcode_t rc; + int size; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_LOV) return 0; - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_LOV + strlen("trusted."), - (char *)lum, loa->loa_lum_size, &size); - if (rc) { - LS3_DEBUG_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_LOV, rc); - rc = -ENODATA; + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LOV, lum, loa->loa_lum_size, &size); + if (rc < 0) goto out; - } layout = llapi_layout_get_by_xattr(lum, size, 0); if (layout == NULL) { - LS3_ERROR_OBJ(lo, "cannot decode '%s' xattr: rc = %ld\n", + LS3_ERROR_OBJ(lo, "cannot decode '%s' xattr: rc = %d\n", XATTR_NAME_LOV, rc); rc = -errno; goto out; @@ -409,29 +401,17 @@ static int ldiskfs_read_attr_lmv(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; int size; - errcode_t rc; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_LMV) return 0; memset(loa->loa_lmv_buf, 0, sizeof(loa->loa_lmv_buf)); - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_LMV + strlen("trusted."), - loa->loa_lmv_buf, sizeof(loa->loa_lmv_buf), - &size); - if (xattr_name_not_found(rc)) { - LS3_DEBUG_OBJ(lo, "has no '%s' xattr ignoring rc = %ld\n", - XATTR_NAME_LMV, rc); - return 1; /* XXX */ - } else if (rc) { - LS3_ERROR_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_LMV, rc); - return -ENODATA; - } + + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_LMV, loa->loa_lmv_buf, sizeof(loa->loa_lmv_buf), &size); + if (rc < 0) + return rc; loa->loa_attr_bits |= LS3_OBJECT_ATTR_LMV; @@ -460,39 +440,25 @@ static int ldiskfs_read_attr_hsm(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; struct hsm_user_state *hus = &loa->loa_hsm_state; char buf[XATTR_SIZE_MAX]; - int size; struct hsm_attrs *hsm; - errcode_t rc; + int size; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_HSM) return 0; assert(sizeof(*hsm) < XATTR_SIZE_MAX); - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_HSM + strlen("trusted."), - buf, sizeof(buf), &size); - if (xattr_name_not_found(rc)) { - LS3_DEBUG_OBJ(lo, "has no '%s' xattr\n", XATTR_NAME_HSM); - hus->hus_states = 0; - hus->hus_archive_id = 0; - return -ENODATA; - } - - if (rc != 0) { - LS3_ERROR_OBJ(lo, "cannot get '%s' xattr: rc = %s\n", - XATTR_NAME_HSM, xstrerror(rc)); + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_HSM, buf, sizeof(buf), &size); + if (rc < 0) return rc; - } hsm = (struct hsm_attrs *)buf; hus->hus_states = ext2fs_le32_to_cpu(hsm->hsm_flags); hus->hus_archive_id = ext2fs_le64_to_cpu(hsm->hsm_arch_id); + loa->loa_attr_bits |= LS3_OBJECT_ATTR_HSM; return 0; @@ -502,24 +468,16 @@ static int ldiskfs_read_attr_som(struct ls3_instance *li, struct lipe_object *lo, struct ls3_object_attrs *loa) { - ext2_filsys fs = lo->u.lo_ldiskfs.lol_fs; - struct ext2_inode_large *inode = lo->u.lo_ldiskfs.lol_inode; - int size; struct lustre_som_attrs *som = &loa->loa_som; - errcode_t rc; + int size; + int rc; if (loa->loa_attr_bits & LS3_OBJECT_ATTR_SOM) return 0; - rc = ext2fs_attr_get(fs, (struct ext2_inode *)inode, - EXT2_ATTR_INDEX_TRUSTED, - XATTR_NAME_SOM + strlen("trusted."), - (char *)som, sizeof(*som), &size); - if (rc) { - LS3_DEBUG_OBJ(lo, "cannot get '%s' xattr: rc = %ld\n", - XATTR_NAME_SOM, rc); - return -ENODATA; - } + rc = ldiskfs_trusted_xattr_get(lo, XATTR_NAME_SOM, som, sizeof(*som), &size); + if (rc < 0) + return rc; if (size != sizeof(*som)) { LS3_ERROR_OBJ(lo, "unexpected size of '%s' xattr, expected %zu, got %d\n", -- 1.8.3.1