From 9ead7830a599e94abd819c94f41ef4e6fb06d289 Mon Sep 17 00:00:00 2001 From: jcl Date: Wed, 15 May 2013 13:16:41 +0200 Subject: [PATCH 1/1] LU-3345 llapi: add user space method for lov_user_md move lov_mds_md_size from obd_lov.h to lustre_idl.h to have it close to lov_mds_md definition. add lov_user_md_size() to compute lum size so llapi and user space utils do not use kernel internal definitions/methods Signed-off-by: JC Lafoucriere Change-Id: I01825efb4521bf90293239054a32fd66f85bcaf2 Reviewed-on: http://review.whamcloud.com/6345 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Jinshan Xiong Reviewed-by: Andreas Dilger --- lustre/include/lustre/lustre_idl.h | 11 +++++++++++ lustre/include/lustre/lustre_user.h | 10 ++++++++++ lustre/include/obd_lov.h | 10 ---------- lustre/tests/ll_dirstripe_verify.c | 17 +++++++++-------- lustre/utils/lfs.c | 2 +- lustre/utils/liblustreapi.c | 4 ++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index b9fd5a7..174fd42 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -1674,6 +1674,17 @@ struct lov_mds_md_v3 { /* LOV EA mds/wire data (little-endian) */ struct lov_ost_data_v1 lmm_objects[0]; /* per-stripe data */ }; +static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic) +{ + if (lmm_magic == LOV_MAGIC_V3) + return sizeof(struct lov_mds_md_v3) + + stripes * sizeof(struct lov_ost_data_v1); + else + return sizeof(struct lov_mds_md_v1) + + stripes * sizeof(struct lov_ost_data_v1); +} + + #define OBD_MD_FLID (0x00000001ULL) /* object ID */ #define OBD_MD_FLATIME (0x00000002ULL) /* access time */ #define OBD_MD_FLMTIME (0x00000004ULL) /* data modification time */ diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 4b74f94..9de0815 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -358,6 +358,16 @@ struct lov_user_md_v3 { /* LOV EA user data (host-endian) */ struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */ } __attribute__((packed)); +static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic) +{ + if (lmm_magic == LOV_USER_MAGIC_V3) + return sizeof(struct lov_user_md_v3) + + stripes * sizeof(struct lov_user_ost_data_v1); + else + return sizeof(struct lov_user_md_v1) + + stripes * sizeof(struct lov_user_ost_data_v1); +} + /* Compile with -D_LARGEFILE64_SOURCE or -D_GNU_SOURCE (or #define) to * use this. It is unsafe to #define those values in this header as it * is possible the application has already #included . */ diff --git a/lustre/include/obd_lov.h b/lustre/include/obd_lov.h index 1ee3675..dfb2631 100644 --- a/lustre/include/obd_lov.h +++ b/lustre/include/obd_lov.h @@ -44,16 +44,6 @@ static inline int lov_stripe_md_size(__u16 stripes) return sizeof(struct lov_stripe_md) + stripes*sizeof(struct lov_oinfo*); } -static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic) -{ - if (lmm_magic == LOV_MAGIC_V3) - return sizeof(struct lov_mds_md_v3) + - stripes * sizeof(struct lov_ost_data_v1); - else - return sizeof(struct lov_mds_md_v1) + - stripes * sizeof(struct lov_ost_data_v1); -} - struct lov_version_size { __u32 lvs_magic; size_t lvs_lmm_size; diff --git a/lustre/tests/ll_dirstripe_verify.c b/lustre/tests/ll_dirstripe_verify.c index 9a98b9f..d5269b4 100644 --- a/lustre/tests/ll_dirstripe_verify.c +++ b/lustre/tests/ll_dirstripe_verify.c @@ -245,14 +245,15 @@ int main(int argc, char **argv) return rc; } - lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC); - if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) { - rc = -ENOMEM; - llapi_error(LLAPI_MSG_ERROR, rc, - "error: can't allocate %d bytes " - "for dir EA", lum_size); - goto cleanup; - } + lum_size = lov_user_md_size(MAX_LOV_UUID_COUNT, LOV_USER_MAGIC); + lum_dir = (struct lov_user_md *)malloc(lum_size); + if (lum_dir == NULL) { + rc = -ENOMEM; + llapi_error(LLAPI_MSG_ERROR, rc, + "error: can't allocate %d bytes " + "for dir EA", lum_size); + goto cleanup; + } rc = llapi_file_get_stripe(argv[1], lum_dir); if (rc) { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 5b2e45e..f258453 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -355,7 +355,7 @@ static int lfs_migrate(char *name, unsigned long long stripe_size, int have_gl = 0; /* find the right size for the IO and allocate the buffer */ - lumsz = lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3); + lumsz = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3); lum = malloc(lumsz); if (lum == NULL) { rc = -ENOMEM; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 155f5c3..ce51960 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -524,7 +524,7 @@ static int get_param_lmv(const char *path, static int get_mds_md_size(const char *path) { - int md_size = lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3); + int md_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3); char buf[80]; int rc; @@ -3098,7 +3098,7 @@ static int cb_getstripe(char *path, DIR *parent, DIR *d, void *data, * The object_seq needs to be set for the "(Default)" * prefix to be displayed. */ struct lov_user_md *lmm = ¶m->lmd->lmd_lmm; - lmm->lmm_magic = LOV_MAGIC_V1; + lmm->lmm_magic = LOV_USER_MAGIC_V1; if (!param->raw) ostid_set_seq(&lmm->lmm_oi, FID_SEQ_LOV_DEFAULT); -- 1.8.3.1