Whamcloud - gitweb
LU-7225 llite: ladvise protocol changes 66/20666/20
authorPatrick Farrell <paf@cray.com>
Mon, 1 Aug 2016 18:45:10 +0000 (13:45 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 15 Aug 2016 21:09:27 +0000 (21:09 +0000)
This patch makes some changes to the ladvise API and
protocol to support lock ahead and possible future users.

Primarily, it separates the userspace API arguments from
the structures which go out on the network, and adds a
number of 'value' fields without a predefined use.

The meaning of each value field can be different for
different advice types, allowing some extensibility.

Signed-off-by: Patrick Farrell <paf@cray.com>
Change-Id: I7ac18e546f16a20c3c6bc6849becb0d45e3d5dc9
Reviewed-on: http://review.whamcloud.com/20666
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre/lustre_idl.h
lustre/include/lustre/lustre_user.h
lustre/include/lustre/lustreapi.h
lustre/llite/file.c
lustre/ptlrpc/pack_generic.c
lustre/ptlrpc/wiretest.c
lustre/utils/lfs.c
lustre/utils/liblustreapi_ladvise.c
lustre/utils/wirecheck.c
lustre/utils/wiretest.c

index b3c7852..16c0d98 100644 (file)
@@ -3996,5 +3996,31 @@ union nodemap_rec {
        struct nodemap_global_rec ngr;
 };
 
+/* This is the lu_ladvise struct which goes out on the wire.
+ * Corresponds to the userspace arg llapi_lu_ladvise.
+ * value[1-4] are unspecified fields, used differently by different advices */
+struct lu_ladvise {
+       __u16 lla_advice;       /* advice type */
+       __u16 lla_value1;       /* values for different advice types */
+       __u32 lla_value2;
+       __u64 lla_start;        /* first byte of extent for advice */
+       __u64 lla_end;          /* last byte of extent for advice */
+       __u32 lla_value3;
+       __u32 lla_value4;
+};
+
+/* This is the ladvise_hdr which goes on the wire, corresponds to the userspace
+ * arg llapi_ladvise_hdr.
+ * value[1-3] are unspecified fields, used differently by different advices */
+struct ladvise_hdr {
+       __u32                   lah_magic;      /* LADVISE_MAGIC */
+       __u32                   lah_count;      /* number of advices */
+       __u64                   lah_flags;      /* from enum ladvise_flag */
+       __u32                   lah_value1;     /* unused */
+       __u32                   lah_value2;     /* unused */
+       __u64                   lah_value3;     /* unused */
+       struct lu_ladvise       lah_advise[0];  /* advices in this header */
+};
+
 #endif
 /** @} lustreidl */
index 80dbc0b..96226ec 100644 (file)
@@ -294,7 +294,7 @@ struct ll_futimes_3 {
 #define LL_IOC_MIGRATE                 _IOR('f', 247, int)
 #define LL_IOC_FID2MDTIDX              _IOWR('f', 248, struct lu_fid)
 #define LL_IOC_GETPARENT               _IOWR('f', 249, struct getparent)
-#define LL_IOC_LADVISE                 _IOR('f', 250, struct lu_ladvise)
+#define LL_IOC_LADVISE                 _IOR('f', 250, struct llapi_lu_ladvise)
 
 /* Lease types for use as arg and return of LL_IOC_{GET,SET}_LEASE ioctl. */
 enum ll_lease_type {
@@ -1383,11 +1383,17 @@ enum lu_ladvise_type {
 #define LU_LADVISE_NAMES {                                             \
 }
 
-struct lu_ladvise {
-       __u64 lla_advice;
-       __u64 lla_start;
-       __u64 lla_end;
-       __u64 lla_padding;
+/* This is the userspace argument for ladvise.  It is currently the same as
+ * what goes on the wire (struct lu_ladvise), but is defined separately as we
+ * may need info which is only used locally. */
+struct llapi_lu_ladvise {
+       __u16 lla_advice;       /* advice type */
+       __u16 lla_value1;       /* values for different advice types */
+       __u32 lla_value2;
+       __u64 lla_start;        /* first byte of extent for advice */
+       __u64 lla_end;          /* last byte of extent for advice */
+       __u32 lla_value3;
+       __u32 lla_value4;
 };
 
 enum ladvise_flag {
@@ -1397,13 +1403,17 @@ enum ladvise_flag {
 #define LADVISE_MAGIC 0x1ADF1CE0
 #define LF_MASK LF_ASYNC
 
-struct ladvise_hdr {
+/* This is the userspace argument for ladvise, corresponds to ladvise_hdr which
+ * is used on the wire.  It is defined separately as we may need info which is
+ * only used locally. */
+struct llapi_ladvise_hdr {
        __u32                   lah_magic;      /* LADVISE_MAGIC */
        __u32                   lah_count;      /* number of advices */
        __u64                   lah_flags;      /* from enum ladvise_flag */
-       __u64                   lah_padding1;   /* unused */
-       __u64                   lah_padding2;   /* unused */
-       struct lu_ladvise       lah_advise[0];
+       __u32                   lah_value1;     /* unused */
+       __u32                   lah_value2;     /* unused */
+       __u64                   lah_value3;     /* unused */
+       struct llapi_lu_ladvise lah_advise[0];  /* advices in this header */
 };
 
 #define LAH_COUNT_MAX  (1024)
index d94dd03..a1cc6e5 100644 (file)
@@ -408,7 +408,7 @@ int llapi_group_unlock(int fd, int gid);
 
 /* Ladvise */
 int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
-                 struct lu_ladvise *ladvise);
+                 struct llapi_lu_ladvise *ladvise);
 /** @} llapi */
 
 /* llapi_layout user interface */
index 37f516d..9531c50 100644 (file)
@@ -2293,7 +2293,7 @@ static int ll_file_futimes_3(struct file *file, const struct ll_futimes_3 *lfu)
  * much more data being sent to the client.
  */
 static int ll_ladvise(struct inode *inode, struct file *file, __u64 flags,
-                     struct lu_ladvise *ladvise)
+                     struct llapi_lu_ladvise *ladvise)
 {
        struct lu_env *env;
        struct cl_io *io;
@@ -2673,7 +2673,7 @@ out:
                RETURN(ll_file_futimes_3(file, &lfu));
        }
        case LL_IOC_LADVISE: {
-               struct ladvise_hdr *ladvise_hdr;
+               struct llapi_ladvise_hdr *ladvise_hdr;
                int i;
                int num_advise;
                int alloc_size = sizeof(*ladvise_hdr);
@@ -2684,7 +2684,7 @@ out:
                        RETURN(-ENOMEM);
 
                if (copy_from_user(ladvise_hdr,
-                                  (const struct ladvise_hdr __user *)arg,
+                                  (const struct llapi_ladvise_hdr __user *)arg,
                                   alloc_size))
                        GOTO(out_ladvise, rc = -EFAULT);
 
@@ -2707,7 +2707,7 @@ out:
                 * TODO: submit multiple advices to one server in a single RPC
                 */
                if (copy_from_user(ladvise_hdr,
-                                  (const struct ladvise_hdr __user *)arg,
+                                  (const struct llapi_ladvise_hdr __user *)arg,
                                   alloc_size))
                        GOTO(out_ladvise, rc = -EFAULT);
 
index 199383c..d91bdf1 100644 (file)
@@ -2630,10 +2630,13 @@ EXPORT_SYMBOL(lustre_swab_orphan_ent);
 
 void lustre_swab_ladvise(struct lu_ladvise *ladvise)
 {
+       __swab16s(&ladvise->lla_advice);
+       __swab16s(&ladvise->lla_value1);
+       __swab32s(&ladvise->lla_value2);
        __swab64s(&ladvise->lla_start);
        __swab64s(&ladvise->lla_end);
-       __swab64s(&ladvise->lla_advice);
-       CLASSERT(offsetof(typeof(*ladvise), lla_padding) != 0);
+       __swab32s(&ladvise->lla_value3);
+       __swab32s(&ladvise->lla_value4);
 }
 EXPORT_SYMBOL(lustre_swab_ladvise);
 
@@ -2642,7 +2645,8 @@ void lustre_swab_ladvise_hdr(struct ladvise_hdr *ladvise_hdr)
        __swab32s(&ladvise_hdr->lah_magic);
        __swab32s(&ladvise_hdr->lah_count);
        __swab64s(&ladvise_hdr->lah_flags);
-       CLASSERT(offsetof(typeof(*ladvise_hdr), lah_padding1) != 0);
-       CLASSERT(offsetof(typeof(*ladvise_hdr), lah_padding2) != 0);
+       __swab32s(&ladvise_hdr->lah_value1);
+       __swab32s(&ladvise_hdr->lah_value2);
+       __swab64s(&ladvise_hdr->lah_value3);
 }
 EXPORT_SYMBOL(lustre_swab_ladvise_hdr);
index 02d6624..e496dfb 100644 (file)
@@ -4987,8 +4987,16 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(struct lu_ladvise));
        LASSERTF((int)offsetof(struct lu_ladvise, lla_advice) == 0, "found %lld\n",
                 (long long)(int)offsetof(struct lu_ladvise, lla_advice));
-       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_advice) == 8, "found %lld\n",
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_advice) == 2, "found %lld\n",
                 (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_advice));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value1) == 2, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value1));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value1) == 2, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value1));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value2) == 4, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value2));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value2) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value2));
        LASSERTF((int)offsetof(struct lu_ladvise, lla_start) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct lu_ladvise, lla_start));
        LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_start) == 8, "found %lld\n",
@@ -4997,10 +5005,14 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lu_ladvise, lla_end));
        LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_end) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_end));
-       LASSERTF((int)offsetof(struct lu_ladvise, lla_padding) == 24, "found %lld\n",
-                (long long)(int)offsetof(struct lu_ladvise, lla_padding));
-       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_padding) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_padding));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value3) == 24, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value3));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value3) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value3));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value4) == 28, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value4));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value4) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value4));
 
        /* Checks for struct ladvise_hdr */
        LASSERTF(LADVISE_MAGIC == 0x1ADF1CE0, "found 0x%.8x\n",
@@ -5019,14 +5031,18 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct ladvise_hdr, lah_flags));
        LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_flags) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_flags));
-       LASSERTF((int)offsetof(struct ladvise_hdr, lah_padding1) == 16, "found %lld\n",
-                (long long)(int)offsetof(struct ladvise_hdr, lah_padding1));
-       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_padding1) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_padding1));
-       LASSERTF((int)offsetof(struct ladvise_hdr, lah_padding2) == 24, "found %lld\n",
-                (long long)(int)offsetof(struct ladvise_hdr, lah_padding2));
-       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_padding2) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_padding2));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value1) == 16, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value1));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value1) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value1));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value2) == 20, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value2));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value2) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value2));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value3) == 24, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value3));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value3) == 8, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value3));
        LASSERTF((int)offsetof(struct ladvise_hdr, lah_advise) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct ladvise_hdr, lah_advise));
        LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_advise) == 0, "found %lld\n",
index 8776d2f..3c5aefa 100644 (file)
@@ -4273,7 +4273,7 @@ static int lfs_ladvise(int argc, char **argv)
        int                      rc = 0;
        const char              *path;
        int                      fd;
-       struct lu_ladvise        advice;
+       struct llapi_lu_ladvise  advice;
        enum lu_ladvise_type     advice_type = LU_LADVISE_INVALID;
        unsigned long long       start = 0;
        unsigned long long       end = LUSTRE_EOF;
@@ -4397,7 +4397,10 @@ static int lfs_ladvise(int argc, char **argv)
                advice.lla_start = start;
                advice.lla_end = end;
                advice.lla_advice = advice_type;
-               advice.lla_padding = 0;
+               advice.lla_value1 = 0;
+               advice.lla_value2 = 0;
+               advice.lla_value3 = 0;
+               advice.lla_value4 = 0;
                rc2 = llapi_ladvise(fd, flags, 1, &advice);
                close(fd);
                if (rc2 < 0) {
index 85083f1..b606dfe 100644 (file)
  * \param ladvise  Advice to give.
  *
  * \retval 0 on success.
- * \retval -errno on failure.
+ * \retval -1 on failure, errno set
  */
 int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
-                 struct lu_ladvise *ladvise)
+                 struct llapi_lu_ladvise *ladvise)
 {
        int rc;
-       struct ladvise_hdr *ladvise_hdr;
+       struct llapi_ladvise_hdr *ladvise_hdr;
 
        if (num_advise < 1 || num_advise >= LAH_COUNT_MAX) {
                errno = EINVAL;
index 65831c1..029de8b 100644 (file)
@@ -316,10 +316,16 @@ check_lu_ladvise(void)
 {
        BLANK_LINE();
        CHECK_STRUCT(lu_ladvise);
+       CHECK_MEMBER(lu_ladvise, lla_advice);
+       CHECK_MEMBER(lu_ladvise, lla_value1);
+       CHECK_MEMBER(lu_ladvise, lla_value2);
        CHECK_MEMBER(lu_ladvise, lla_start);
        CHECK_MEMBER(lu_ladvise, lla_end);
-       CHECK_MEMBER(lu_ladvise, lla_advice);
-       CHECK_MEMBER(lu_ladvise, lla_padding);
+       CHECK_MEMBER(lu_ladvise, lla_value3);
+       CHECK_MEMBER(lu_ladvise, lla_value4);
+
+       CHECK_VALUE(LF_ASYNC);
+       CHECK_VALUE(LADVISE_MAGIC);
 }
 
 static void
index 1ae1cdf..1cf7c04 100644 (file)
@@ -5002,8 +5002,16 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)sizeof(struct lu_ladvise));
        LASSERTF((int)offsetof(struct lu_ladvise, lla_advice) == 0, "found %lld\n",
                 (long long)(int)offsetof(struct lu_ladvise, lla_advice));
-       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_advice) == 8, "found %lld\n",
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_advice) == 2, "found %lld\n",
                 (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_advice));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value1) == 2, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value1));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value1) == 2, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value1));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value2) == 4, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value2));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value2) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value2));
        LASSERTF((int)offsetof(struct lu_ladvise, lla_start) == 8, "found %lld\n",
                 (long long)(int)offsetof(struct lu_ladvise, lla_start));
        LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_start) == 8, "found %lld\n",
@@ -5012,10 +5020,14 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lu_ladvise, lla_end));
        LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_end) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_end));
-       LASSERTF((int)offsetof(struct lu_ladvise, lla_padding) == 24, "found %lld\n",
-                (long long)(int)offsetof(struct lu_ladvise, lla_padding));
-       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_padding) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_padding));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value3) == 24, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value3));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value3) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value3));
+       LASSERTF((int)offsetof(struct lu_ladvise, lla_value4) == 28, "found %lld\n",
+                (long long)(int)offsetof(struct lu_ladvise, lla_value4));
+       LASSERTF((int)sizeof(((struct lu_ladvise *)0)->lla_value4) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct lu_ladvise *)0)->lla_value4));
 
        /* Checks for struct ladvise_hdr */
        LASSERTF(LADVISE_MAGIC == 0x1ADF1CE0, "found 0x%.8x\n",
@@ -5034,14 +5046,18 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct ladvise_hdr, lah_flags));
        LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_flags) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_flags));
-       LASSERTF((int)offsetof(struct ladvise_hdr, lah_padding1) == 16, "found %lld\n",
-                (long long)(int)offsetof(struct ladvise_hdr, lah_padding1));
-       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_padding1) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_padding1));
-       LASSERTF((int)offsetof(struct ladvise_hdr, lah_padding2) == 24, "found %lld\n",
-                (long long)(int)offsetof(struct ladvise_hdr, lah_padding2));
-       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_padding2) == 8, "found %lld\n",
-                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_padding2));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value1) == 16, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value1));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value1) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value1));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value2) == 20, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value2));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value2) == 4, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value2));
+       LASSERTF((int)offsetof(struct ladvise_hdr, lah_value3) == 24, "found %lld\n",
+                (long long)(int)offsetof(struct ladvise_hdr, lah_value3));
+       LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_value3) == 8, "found %lld\n",
+                (long long)(int)sizeof(((struct ladvise_hdr *)0)->lah_value3));
        LASSERTF((int)offsetof(struct ladvise_hdr, lah_advise) == 32, "found %lld\n",
                 (long long)(int)offsetof(struct ladvise_hdr, lah_advise));
        LASSERTF((int)sizeof(((struct ladvise_hdr *)0)->lah_advise) == 0, "found %lld\n",