Whamcloud - gitweb
LU-18212 ioctl: LL_IOC_FID2MDTIDX on server mount point 39/56339/2
authorAlex Zhuravlev <bzzz@whamcloud.com>
Sat, 24 Aug 2024 15:37:48 +0000 (23:37 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 16 Sep 2024 15:13:38 +0000 (15:13 +0000)
add LL_IOC_FID2MDTIDX ioctl support on server's mount point.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: If3c8c96e75573b812688686a331a38250826cd05
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56339
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/obd.h
lustre/osd-ldiskfs/osd_handler.c
lustre/target/tgt_mount.c

index 58e1160..faebcf6 100644 (file)
@@ -853,6 +853,7 @@ static inline bool obd_mdt_recovery_abort(struct obd_device *obd)
 
 #define KEY_CACHE_LRU_SHRINK   "cache_lru_shrink"
 #define KEY_OSP_CONNECTED      "osp_connected"
+#define KEY_FID2IDX            "fid2idx"
 
 #define KEY_UNEVICT_CACHE_SHRINK       "unevict_cache_shrink"
 
index 4892f1b..54d369e 100644 (file)
@@ -8889,6 +8889,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.
  */
@@ -8897,6 +8933,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 delayed_unlink_mb_show(struct kobject *kobj,
index beefbbf..c62d76e 100644 (file)
@@ -49,6 +49,7 @@
 #ifdef HAVE_FSMAP_H
 #include <linux/fsmap.h>
 #endif
+#include <linux/uaccess.h>
 
 #include <llog_swab.h>
 #include <lustre_disk.h>
@@ -2009,6 +2010,40 @@ static long server_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        struct inode *root_inode;
        int err = -ENOTTY;
 
+       if (cmd == 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_cmd_supported(cmd))
                return err;