From 790f97bf75df6282f224f5f9c04808f75e809b4d Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Wed, 16 Oct 2019 17:38:12 +0300 Subject: [PATCH] EX-603 ioctl: LL_IOC_FID2MDTIDX on server mount point add LL_IOC_FID2MDTIDX ioctl support on server's mount point. this way lpurge can lookup MDS# by FID w/o Lustre client, so lpurge won't need Lustre client on OSTs. Signed-off-by: Alex Zhuravlev Change-Id: If3c8c96e75573b812688686a331a38250826cd05 Reviewed-by: Andreas Dilger Reviewed-by: Gu Zheng Reviewed-on: https://review.whamcloud.com/41832 Tested-by: jenkins Tested-by: Maloo --- lustre/include/obd.h | 1 + lustre/obdclass/obd_mount_server.c | 35 +++++++++++++++++++++++++++++++++++ lustre/osd-ldiskfs/osd_handler.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 3adc7db..774bd35 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -801,6 +801,7 @@ void obd_nid_del(struct obd_device *obd, struct obd_export *exp); #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink" #define KEY_OSP_CONNECTED "osp_connected" +#define KEY_FID2IDX "fid2idx" /* Flags for op_xvalid */ enum op_xvalid { diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index fa4de07..beaa6d1 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -1833,6 +1834,40 @@ static long server_ioctl(struct file *filp, unsigned int command, struct inode *active_inode; int err = -EOPNOTSUPP; + if (command == LL_IOC_FID2MDTIDX) { + union { + struct lu_seq_range range; + struct lu_fid fid; + } u; + struct lu_env *env; + int len; + + if (copy_from_user(&u.fid, (struct lu_fid __user *)arg, + sizeof(u.fid))) + RETURN(-EFAULT); + + OBD_ALLOC_PTR(env); + if (env == NULL) + return -ENOMEM; + err = lu_env_init(env, LCT_DT_THREAD); + if (err) + GOTO(out, err = -ENOMEM); + + /* XXX: check for size */ + len = sizeof(struct lu_fid); + err = obd_get_info(env, lsi->lsi_osd_exp, sizeof(KEY_FID2IDX), + KEY_FID2IDX, &len, &u.fid); + if (err == 0) { + err = -EINVAL; + if (u.range.lsr_flags & LU_SEQ_RANGE_MDT) + err = u.range.lsr_index; + } + lu_env_fini(env); +out: + OBD_FREE_PTR(env); + return err; + } + if (IS_ERR(dd_sb) || !is_cmd_supported(command)) return err; diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 9a18ea8..2581351 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -8284,6 +8284,42 @@ static int osd_health_check(const struct lu_env *env, struct obd_device *obd) return (osd->od_mnt == NULL || sb->s_flags & SB_RDONLY); } +static int osd_get_info(const struct lu_env *env, struct obd_export *exp, + __u32 keylen, void *key, __u32 *vallen, void *val) +{ + struct osd_device *osd; + int rc = -EINVAL; + + ENTRY; + + if (!exp->exp_obd) { + CDEBUG(D_IOCTL, "invalid client export %p\n", exp); + RETURN(-EINVAL); + } + osd = osd_dev(exp->exp_obd->obd_lu_dev); + + if (KEY_IS(KEY_FID2IDX)) { + struct lu_seq_range range; + struct lu_fid fid; + + if (osd_seq_site(osd)->ss_server_fld == NULL) + RETURN(-EINPROGRESS); + + LASSERT(*vallen = sizeof(struct lu_fid)); + memcpy(&fid, val, sizeof(struct lu_fid)); + + fld_range_set_any(&range); + + rc = osd_fld_lookup(env, osd, fid_seq(&fid), &range); + if (rc == 0) { + memcpy(val, &range, sizeof(range)); + *vallen = sizeof(range); + } + } + + RETURN(rc); +} + /* * lprocfs legacy support. */ @@ -8292,6 +8328,7 @@ static const struct obd_ops osd_obd_device_ops = { .o_connect = osd_obd_connect, .o_disconnect = osd_obd_disconnect, .o_health_check = osd_health_check, + .o_get_info = osd_get_info, }; static ssize_t track_declares_assert_show(struct kobject *kobj, -- 1.8.3.1