Whamcloud - gitweb
EX-603 ioctl: LL_IOC_FID2MDTIDX on server mount point
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 16 Oct 2019 14:38:12 +0000 (17:38 +0300)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 5 Mar 2021 18:49:30 +0000 (18:49 +0000)
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 <bzzz@whamcloud.com>
Change-Id: If3c8c96e75573b812688686a331a38250826cd05
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Gu Zheng <gzheng@ddn.com>
Reviewed-on: https://review.whamcloud.com/41832
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/obd.h
lustre/obdclass/obd_mount_server.c
lustre/osd-ldiskfs/osd_handler.c

index 3adc7db..774bd35 100644 (file)
@@ -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 {
index fa4de07..beaa6d1 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/statfs.h>
 #include <linux/version.h>
 #include <linux/delay.h>
+#include <linux/uaccess.h>
 
 #include <llog_swab.h>
 #include <lustre_disk.h>
@@ -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;
 
index 9a18ea8..2581351 100644 (file)
@@ -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,