From 5f2024dbcd81a4492c084710cc959da6c25579fb Mon Sep 17 00:00:00 2001 From: Fan Yong Date: Fri, 16 May 2014 04:09:12 +0800 Subject: [PATCH] LU-5223 lod: generate linkEA for shard of striped directory Otherwise, it will misguide namespace LFSCK to regard it as the case of linkEA corrupted or upgraded from 1.8 device, then cause improper reparing or status reporting. On the other hand, the linkEA for slave object of striped directory will also be used for fid2path in subsequent patches. Signed-off-by: Fan Yong Change-Id: I877b091eb330df0283de2ea21f2796387023da30 Reviewed-on: http://review.whamcloud.com/10765 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: wangdi Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev --- lustre/lod/lod_dev.c | 1 + lustre/lod/lod_internal.h | 19 ++++++++++++++---- lustre/lod/lod_object.c | 49 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index e63c6ed..9ab7972 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -814,6 +814,7 @@ static void lod_key_fini(const struct lu_context *ctx, info->lti_ea_store = NULL; info->lti_ea_store_size = 0; } + lu_buf_free(&info->lti_linkea_buf); OBD_FREE_PTR(info); } diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index af1457c..ac1d256 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -278,11 +278,11 @@ struct lod_thread_info { struct lu_attr lti_attr; struct lod_it lti_it; struct ldlm_res_id lti_res_id; - - /* used to hold lu_dirent, NAME_MAX + sizeof(struct lu_dirent) */ - char lti_key[NAME_MAX + sizeof(struct lu_dirent)]; - + /* used to hold lu_dirent, sizeof(struct lu_dirent) + NAME_MAX */ + char lti_key[sizeof(struct lu_dirent) + NAME_MAX]; struct dt_object_format lti_format; + struct lu_name lti_name; + struct lu_buf lti_linkea_buf; }; extern const struct lu_device_operations lod_lu_ops; @@ -358,6 +358,17 @@ static inline struct lod_thread_info *lod_env_info(const struct lu_env *env) return info; } +static inline struct lu_name * +lod_name_get(const struct lu_env *env, const void *area, int len) +{ + struct lu_name *lname; + + lname = &lod_env_info(env)->lti_name; + lname->ln_name = area; + lname->ln_namelen = len; + return lname; +} + #define lod_foreach_ost(__dev, index) \ if ((__dev)->lod_osts_size > 0) \ cfs_foreach_bit((__dev)->lod_ost_bitmap, (index)) diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 18c8000..ed457a8 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "lod_internal.h" @@ -1431,8 +1432,11 @@ next: GOTO(out_put, rc = -EINVAL); for (i = 0; i < lo->ldo_stripenr; i++) { - struct dt_object *dto = stripe[i]; - char *stripe_name = info->lti_key; + struct dt_object *dto = stripe[i]; + char *stripe_name = info->lti_key; + struct lu_name *sname; + struct linkea_data ldata = { 0 }; + struct lu_buf linkea_buf; rc = dt_declare_create(env, dto, attr, NULL, dof, th); if (rc != 0) @@ -1499,6 +1503,23 @@ next: snprintf(stripe_name, sizeof(info->lti_key), DFID":%d", PFID(lu_object_fid(&dto->do_lu)), i); + + sname = lod_name_get(env, stripe_name, strlen(stripe_name)); + rc = linkea_data_new(&ldata, &info->lti_linkea_buf); + if (rc != 0) + GOTO(out_put, rc); + + rc = linkea_add_buf(&ldata, sname, lu_object_fid(&dt->do_lu)); + if (rc != 0) + GOTO(out_put, rc); + + linkea_buf.lb_buf = ldata.ld_buf->lb_buf; + linkea_buf.lb_len = ldata.ld_leh->leh_len; + rc = dt_declare_xattr_set(env, dto, &linkea_buf, + XATTR_NAME_LINK, 0, th); + if (rc != 0) + GOTO(out_put, rc); + rc = dt_declare_insert(env, dt_object_child(dt), (const struct dt_rec *)lu_object_fid(&dto->do_lu), (const struct dt_key *)stripe_name, th); @@ -1890,8 +1911,11 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt, slave_lmv_buf.lb_len = sizeof(*slave_lmm); for (i = 0; i < lo->ldo_stripenr; i++) { - struct dt_object *dto; - char *stripe_name = info->lti_key; + struct dt_object *dto; + char *stripe_name = info->lti_key; + struct lu_name *sname; + struct linkea_data ldata = { 0 }; + struct lu_buf linkea_buf; dto = lo->ldo_stripe[i]; dt_write_lock(env, dto, MOR_TGT_CHILD); @@ -1954,6 +1978,23 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt, snprintf(stripe_name, sizeof(info->lti_key), DFID":%d", PFID(lu_object_fid(&dto->do_lu)), i); + + sname = lod_name_get(env, stripe_name, strlen(stripe_name)); + rc = linkea_data_new(&ldata, &info->lti_linkea_buf); + if (rc != 0) + GOTO(out, rc); + + rc = linkea_add_buf(&ldata, sname, lu_object_fid(&dt->do_lu)); + if (rc != 0) + GOTO(out, rc); + + linkea_buf.lb_buf = ldata.ld_buf->lb_buf; + linkea_buf.lb_len = ldata.ld_leh->leh_len; + rc = dt_xattr_set(env, dto, &linkea_buf, XATTR_NAME_LINK, + 0, th, BYPASS_CAPA); + if (rc != 0) + GOTO(out, rc); + rc = dt_insert(env, dt_object_child(dt), (const struct dt_rec *)lu_object_fid(&dto->do_lu), (const struct dt_key *)stripe_name, th, capa, 0); -- 1.8.3.1