Whamcloud - gitweb
LU-13826 utils: fix compatibility for LL_IOC_MDC_GETINFO 58/40858/4
authorQian Yingjin <qian@ddn.com>
Fri, 4 Dec 2020 02:44:25 +0000 (10:44 +0800)
committerOleg Drokin <green@whamcloud.com>
Wed, 9 Dec 2020 17:39:40 +0000 (17:39 +0000)
The landed patch "LU-11367 som: integrate LSOM with lfs find"
uses "LL_IOC_MDC_GETINFO_OLD", so while the IOCTL number/structs
are ABI compatible, it is not API compatible and applications
using for the header including the definition LL_IOC_MDC_GETINFO
is broken.

This patch defines versioned IOCTL number: LL_IOC_MDC_GETINFO_V1,
LL_IOC_MDC_GETINFO_V2. Then we can use the explicitly verioned
constrants everywhere for the in-tree code, and declare
LL_IOC_MDC_GETINFO in a compatible way, but external applications
can select the version that they want explicitly.

And this patch does the same fix for IOC_MDC_GETFILEINFO.

Fixes: 11aa7f8704c4 ("LU-11367 som: integrate LSOM with lfs find")
Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: I39e0273c4a7331ec782de3e8686b8a756e56beec
Reviewed-on: https://review.whamcloud.com/40858
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/dir.c
lustre/utils/liblustreapi.c

index 0bf5480..e3553cf 100644 (file)
@@ -245,8 +245,6 @@ struct statx {
 
 typedef struct statx lstatx_t;
 
-#define HAVE_LOV_USER_MDS_DATA
-
 #define LUSTRE_EOF 0xffffffffffffffffULL
 
 /* for statfs() */
@@ -661,12 +659,12 @@ struct fsxattr {
 #define IOC_MDC_TYPE           'i'
 #define IOC_MDC_LOOKUP         _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
 #define IOC_MDC_GETFILESTRIPE  _IOWR(IOC_MDC_TYPE, 21, struct lov_user_md *)
-#ifdef HAVE_LOV_USER_MDS_DATA
-#define IOC_MDC_GETFILEINFO_OLD        _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data_v1 *)
-#define IOC_MDC_GETFILEINFO    _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data)
-#define LL_IOC_MDC_GETINFO_OLD _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data_v1 *)
-#define LL_IOC_MDC_GETINFO     _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data)
-#endif
+#define IOC_MDC_GETFILEINFO_V1 _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data_v1 *)
+#define IOC_MDC_GETFILEINFO_V2 _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data)
+#define LL_IOC_MDC_GETINFO_V1  _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data_v1 *)
+#define LL_IOC_MDC_GETINFO_V2  _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data)
+#define IOC_MDC_GETFILEINFO    IOC_MDC_GETFILEINFO_V1
+#define LL_IOC_MDC_GETINFO     LL_IOC_MDC_GETINFO_V1
 
 #define MAX_OBD_NAME 128 /* If this changes, a NEW ioctl must be added */
 
@@ -968,7 +966,6 @@ static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
 /* 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 <sys/stat.h>. */
-#ifdef HAVE_LOV_USER_MDS_DATA
 #define lov_user_mds_data lov_user_mds_data_v2
 struct lov_user_mds_data_v1 {
        lstat_t lmd_st;                 /* MDS stat struct */
@@ -983,7 +980,6 @@ struct lov_user_mds_data_v2 {
        __u32 lmd_padding;              /* unused */
        struct lov_user_md_v1 lmd_lmm;  /* LOV EA user data */
 } __attribute__((packed));
-#endif
 
 struct lmv_user_mds_data {
        struct lu_fid   lum_fid;
index ce9758b..dbacb2a 100644 (file)
@@ -1697,10 +1697,10 @@ out_rmdir:
                RETURN(ll_obd_statfs(inode, (void __user *)arg));
        case LL_IOC_LOV_GETSTRIPE:
        case LL_IOC_LOV_GETSTRIPE_NEW:
-       case LL_IOC_MDC_GETINFO:
-       case LL_IOC_MDC_GETINFO_OLD:
-       case IOC_MDC_GETFILEINFO:
-       case IOC_MDC_GETFILEINFO_OLD:
+       case LL_IOC_MDC_GETINFO_V1:
+       case LL_IOC_MDC_GETINFO_V2:
+       case IOC_MDC_GETFILEINFO_V1:
+       case IOC_MDC_GETFILEINFO_V2:
        case IOC_MDC_GETFILESTRIPE: {
                struct ptlrpc_request *request = NULL;
                struct ptlrpc_request *root_request = NULL;
@@ -1715,8 +1715,8 @@ out_rmdir:
                struct lu_fid __user *fidp = NULL;
                int lmmsize;
 
-               if (cmd == IOC_MDC_GETFILEINFO_OLD ||
-                   cmd == IOC_MDC_GETFILEINFO ||
+               if (cmd == IOC_MDC_GETFILEINFO_V1 ||
+                   cmd == IOC_MDC_GETFILEINFO_V2 ||
                    cmd == IOC_MDC_GETFILESTRIPE) {
                        filename = ll_getname((const char __user *)arg);
                        if (IS_ERR(filename))
@@ -1738,10 +1738,10 @@ out_rmdir:
                        GOTO(out_req, rc);
                }
 
-               if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
-                                      cmd == LL_IOC_MDC_GETINFO ||
-                                      cmd == IOC_MDC_GETFILEINFO_OLD ||
-                                      cmd == LL_IOC_MDC_GETINFO_OLD)) {
+               if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
+                                      cmd == LL_IOC_MDC_GETINFO_V1 ||
+                                      cmd == IOC_MDC_GETFILEINFO_V2 ||
+                                      cmd == LL_IOC_MDC_GETINFO_V2)) {
                        lmmsize = 0;
                        rc = 0;
                }
@@ -1753,8 +1753,8 @@ out_rmdir:
                    cmd == LL_IOC_LOV_GETSTRIPE ||
                    cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
                        lump = (struct lov_user_md __user *)arg;
-               } else if (cmd == IOC_MDC_GETFILEINFO_OLD ||
-                          cmd == LL_IOC_MDC_GETINFO_OLD){
+               } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
+                          cmd == LL_IOC_MDC_GETINFO_V1){
                        struct lov_user_mds_data_v1 __user *lmdp;
 
                        lmdp = (struct lov_user_mds_data_v1 __user *)arg;
@@ -1782,8 +1782,8 @@ out_rmdir:
                        rc = -EOVERFLOW;
                }
 
-               if (cmd == IOC_MDC_GETFILEINFO_OLD ||
-                   cmd == LL_IOC_MDC_GETINFO_OLD) {
+               if (cmd == IOC_MDC_GETFILEINFO_V1 ||
+                   cmd == LL_IOC_MDC_GETINFO_V1) {
                        lstat_t st = { 0 };
 
                        st.st_dev       = inode->i_sb->s_dev;
@@ -1804,8 +1804,8 @@ out_rmdir:
 
                        if (copy_to_user(statp, &st, sizeof(st)))
                                GOTO(out_req, rc = -EFAULT);
-               } else if (cmd == IOC_MDC_GETFILEINFO ||
-                          cmd == LL_IOC_MDC_GETINFO) {
+               } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
+                          cmd == LL_IOC_MDC_GETINFO_V2) {
                        lstatx_t stx = { 0 };
                        __u64 valid = body->mbo_valid;
 
@@ -1839,7 +1839,7 @@ out_rmdir:
                         * However, this whould be better decided by the MDS
                         * instead of the client.
                         */
-                       if (cmd == LL_IOC_MDC_GETINFO &&
+                       if (cmd == LL_IOC_MDC_GETINFO_V2 &&
                            ll_i2info(inode)->lli_lsm_md != NULL)
                                valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
 
index 43fd548..5686811 100644 (file)
@@ -2003,20 +2003,21 @@ int get_lmd_info_fd(const char *path, int parent_fd, int dir_fd,
                 * LL_IOC_LOV_GETSTRIPE returns only struct lov_user_md.
                 */
                if (type == GET_LMD_INFO)
-                       cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_OLD :
-                                             LL_IOC_MDC_GETINFO;
+                       cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_V1 :
+                                             LL_IOC_MDC_GETINFO_V2;
                else
                        cmd = LL_IOC_LOV_GETSTRIPE;
 
 retry_getinfo:
                ret = ioctl(dir_fd, cmd, lmdbuf);
-               if (ret < 0 && errno == ENOTTY && cmd == LL_IOC_MDC_GETINFO) {
-                       cmd = LL_IOC_MDC_GETINFO_OLD;
+               if (ret < 0 && errno == ENOTTY &&
+                   cmd == LL_IOC_MDC_GETINFO_V2) {
+                       cmd = LL_IOC_MDC_GETINFO_V1;
                        use_old_ioctl = true;
                        goto retry_getinfo;
                }
 
-               if (cmd == LL_IOC_MDC_GETINFO_OLD && !ret)
+               if (cmd == LL_IOC_MDC_GETINFO_V1 && !ret)
                        ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
        } else if (parent_fd >= 0) {
                const char *fname = strrchr(path, '/');
@@ -2042,21 +2043,21 @@ retry_getinfo:
                        errno = EINVAL;
                else {
                        if (type == GET_LMD_INFO)
-                               cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_OLD :
-                                                     IOC_MDC_GETFILEINFO;
+                               cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_V1 :
+                                                     IOC_MDC_GETFILEINFO_V2;
                        else
                                cmd = IOC_MDC_GETFILESTRIPE;
 
 retry_getfileinfo:
                        ret = ioctl(parent_fd, cmd, lmdbuf);
                        if (ret < 0 && errno == ENOTTY &&
-                           cmd == IOC_MDC_GETFILEINFO) {
-                               cmd = IOC_MDC_GETFILEINFO_OLD;
+                           cmd == IOC_MDC_GETFILEINFO_V2) {
+                               cmd = IOC_MDC_GETFILEINFO_V1;
                                use_old_ioctl = true;
                                goto retry_getfileinfo;
                        }
 
-                       if (cmd == IOC_MDC_GETFILEINFO_OLD && !ret)
+                       if (cmd == IOC_MDC_GETFILEINFO_V1 && !ret)
                                ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
                }
        }