Whamcloud - gitweb
Remove duplicate but unused declaration of mds_pack_open_flags().
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 9bfdbb4..b19b590 100644 (file)
@@ -33,6 +33,8 @@
 #include <linux/obd_support.h>
 #include <linux/obd_class.h>
 #include <linux/lustre_net.h>
+#include <linux/lustre_snap.h>
+#include <linux/fcntl.h>
 
 
 #define HDR_SIZE(count) \
@@ -43,8 +45,7 @@ int lustre_msg_swabbed(struct lustre_msg *msg)
         return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
 }
 
-static void
-lustre_init_msg (struct lustre_msg *msg, int count, int *lens, char **bufs)
+void lustre_init_msg (struct lustre_msg *msg, int count, int *lens, char **bufs)
 {
         char *ptr;
         int   i;
@@ -375,6 +376,171 @@ void lustre_swab_obdo (struct obdo  *o)
         /* o_inline is opaque */
 }
 
+/* mdc pack methods used by mdc and smfs*/
+void *mdc_create_pack(struct lustre_msg *msg, int offset,
+                      struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
+                      const void *data, int datalen)
+{
+        struct mds_rec_create *rec;
+        char *tmp;
+        rec = lustre_msg_buf(msg, offset, sizeof (*rec));
+
+        rec->cr_opcode = REINT_CREATE;
+        rec->cr_fsuid = current->fsuid;
+        rec->cr_fsgid = current->fsgid;
+        rec->cr_cap = current->cap_effective;
+        rec->cr_fid = op_data->fid1;
+        memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
+        rec->cr_mode = mode;
+        rec->cr_rdev = rdev;
+        rec->cr_time = op_data->mod_time;
+        rec->cr_suppgid = op_data->ctxt.gid1;
+
+        tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
+        LOGL0(op_data->name, op_data->namelen, tmp);
+
+        if (data) {
+                tmp = lustre_msg_buf(msg, offset + 2, datalen);
+                memcpy (tmp, data, datalen);
+        }
+        return ((void*)tmp + size_round(datalen));
+}
+
+void *mdc_setattr_pack(struct lustre_msg *msg, struct mdc_op_data *data,
+                       struct iattr *iattr, void *ea, int ealen,
+                       void *ea2, int ea2len)
+{
+        struct mds_rec_setattr *rec = lustre_msg_buf(msg, 0, sizeof (*rec));
+        char *tmp = NULL;
+
+        rec->sa_opcode = REINT_SETATTR;
+        rec->sa_fsuid = current->fsuid;
+        rec->sa_fsgid = current->fsgid;
+        rec->sa_cap = current->cap_effective;
+        rec->sa_fid = data->fid1;
+
+        if (iattr) {
+                rec->sa_valid = iattr->ia_valid;
+                rec->sa_mode = iattr->ia_mode;
+                rec->sa_uid = iattr->ia_uid;
+                rec->sa_gid = iattr->ia_gid;
+                rec->sa_size = iattr->ia_size;
+                rec->sa_atime = LTIME_S(iattr->ia_atime);
+                rec->sa_mtime = LTIME_S(iattr->ia_mtime);
+                rec->sa_ctime = LTIME_S(iattr->ia_ctime);
+                rec->sa_attr_flags = iattr->ia_attr_flags;
+                if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
+                        rec->sa_suppgid = iattr->ia_gid;
+                else if ((iattr->ia_valid & ATTR_MODE) &&
+                         in_group_p(iattr->ia_gid))
+                        rec->sa_suppgid = data->ctxt.gid1;
+                else if ((iattr->ia_valid & (ATTR_MTIME|ATTR_CTIME)) &&
+                         data->ctxt.gid1 != -1)
+                        rec->sa_suppgid = data->ctxt.gid1;
+        }
+        tmp = (char*)rec + size_round(sizeof(*rec));
+                
+        if (ealen == 0)
+                return (void*)tmp;
+
+        memcpy(lustre_msg_buf(msg, 1, ealen), ea, ealen);
+        
+        tmp += size_round(ealen);
+
+        if (ea2len == 0)
+                return (void*)tmp;
+
+        tmp += size_round(ea2len);
+        memcpy(lustre_msg_buf(msg, 2, ea2len), ea2, ea2len);
+        
+        return (void*)tmp;
+}
+
+void *mdc_unlink_pack(struct lustre_msg *msg, int offset,
+                     struct mdc_op_data *data)
+{
+        struct mds_rec_unlink *rec;
+        char *tmp;
+
+        rec = lustre_msg_buf(msg, offset, sizeof (*rec));
+        LASSERT (rec != NULL);
+
+        rec->ul_opcode = REINT_UNLINK;
+        rec->ul_fsuid = current->fsuid;
+        rec->ul_fsgid = current->fsgid;
+        rec->ul_cap = current->cap_effective;
+        rec->ul_mode = data->create_mode;
+        rec->ul_suppgid = data->ctxt.gid1;
+        rec->ul_fid1 = data->fid1;
+        rec->ul_fid2 = data->fid2;
+        rec->ul_time = data->mod_time;
+
+        tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
+        LASSERT (tmp != NULL);
+        LOGL0(data->name, data->namelen, tmp);
+        return (void*)tmp;        
+}
+
+void *mdc_link_pack(struct lustre_msg *msg, int offset,
+                  struct mdc_op_data *data)
+{
+        struct mds_rec_link *rec;
+        char *tmp;
+
+        rec = lustre_msg_buf(msg, offset, sizeof (*rec));
+
+        rec->lk_opcode = REINT_LINK;
+        rec->lk_fsuid = current->fsuid;
+        rec->lk_fsgid = current->fsgid;
+        rec->lk_cap = current->cap_effective;
+        rec->lk_suppgid1 = data->ctxt.gid1;
+        rec->lk_suppgid2 = data->ctxt.gid2;
+        rec->lk_fid1 = data->fid1;
+        rec->lk_fid2 = data->fid2;
+        rec->lk_time = data->mod_time;
+
+        tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
+        LOGL0(data->name, data->namelen, tmp);
+        
+        return (void*)tmp; 
+}
+
+void *mdc_rename_pack(struct lustre_msg *msg, int offset,
+                      struct mdc_op_data *data,
+                      const char *old, int oldlen, const char *new, int newlen)
+{
+        struct mds_rec_rename *rec;
+        char *tmp;
+
+        rec = lustre_msg_buf(msg, offset, sizeof (*rec));
+
+        /* XXX do something about time, uid, gid */
+        rec->rn_opcode = REINT_RENAME;
+        rec->rn_fsuid = current->fsuid;
+        rec->rn_fsgid = current->fsgid;
+        rec->rn_cap = current->cap_effective;
+        if (in_group_p(data->ctxt.gid1))
+                rec->rn_suppgid1 = data->ctxt.gid1;
+        else
+                rec->rn_suppgid1 = -1;
+        if (in_group_p(data->ctxt.gid2))
+                rec->rn_suppgid2 = data->ctxt.gid2;
+        else
+                rec->rn_suppgid2 = -1;
+        rec->rn_fid1 = data->fid1;
+        rec->rn_fid2 = data->fid2;
+        rec->rn_time = data->mod_time;
+
+        tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
+        LOGL0(old, oldlen, tmp);
+
+        if (new) {
+                tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
+                LOGL0(new, newlen, tmp);
+        }
+        return (void*)tmp;
+}
+
 void lustre_swab_obd_statfs (struct obd_statfs *os)
 {
         __swab64s (&os->os_type);
@@ -460,7 +626,11 @@ void lustre_swab_mds_body (struct mds_body *b)
         __swab32s (&b->suppgid);
         __swab32s (&b->eadatasize);
 }
-
+void lustre_swab_clonefs_info (struct clonefs_info *clone)
+{
+       __swab32s(&clone->clone_index);
+       __swab32s(&clone->clone_flags); 
+}
 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
 {
         __swab32s (&sa->sa_opcode);
@@ -671,7 +841,7 @@ void lustre_assert_wire_constants(void)
          * running on Linux schnapps.adilger.int 2.4.22-l32 #4 Thu Jan 8 14:32:57 MST 2004 i686 i686 
          * with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) */
 
-
+#if 0
         /* Constants... */
         LASSERTF(PTLRPC_MSG_MAGIC == 0x0BD00BD0," found %lld\n",
                  (long long)PTLRPC_MSG_MAGIC);
@@ -775,7 +945,7 @@ void lustre_assert_wire_constants(void)
                  (long long)REINT_RENAME);
         LASSERTF(REINT_OPEN == 6, " found %lld\n",
                  (long long)REINT_OPEN);
-        LASSERTF(REINT_MAX == 6, " found %lld\n",
+        LASSERTF(REINT_MAX == 8, " found %lld\n",
                  (long long)REINT_MAX);
         LASSERTF(DISP_IT_EXECD == 1, " found %lld\n",
                  (long long)DISP_IT_EXECD);
@@ -909,7 +1079,7 @@ void lustre_assert_wire_constants(void)
                  (long long)(int)sizeof(((struct lustre_msg *)0)->buflens[7]));
 
         /* Checks for struct obdo */
-        LASSERTF((int)sizeof(struct obdo) == 168, " found %lld\n",
+        LASSERTF((int)sizeof(struct obdo) == 172, " found %lld\n",
                  (long long)(int)sizeof(struct obdo));
         LASSERTF(offsetof(struct obdo, o_id) == 0, " found %lld\n",
                  (long long)offsetof(struct obdo, o_id));
@@ -983,7 +1153,7 @@ void lustre_assert_wire_constants(void)
                  (long long)offsetof(struct obdo, o_easize));
         LASSERTF((int)sizeof(((struct obdo *)0)->o_easize) == 4, " found %lld\n",
                  (long long)(int)sizeof(((struct obdo *)0)->o_easize));
-        LASSERTF(offsetof(struct obdo, o_inline) == 104, " found %lld\n",
+        LASSERTF(offsetof(struct obdo, o_inline) == 108, " found %lld\n",
                  (long long)offsetof(struct obdo, o_inline));
         LASSERTF((int)sizeof(((struct obdo *)0)->o_inline) == 64, " found %lld\n",
                  (long long)(int)sizeof(((struct obdo *)0)->o_inline));
@@ -1193,15 +1363,15 @@ void lustre_assert_wire_constants(void)
                  (long long)OBD_BRW_FROM_GRANT);
 
         /* Checks for struct ost_body */
-        LASSERTF((int)sizeof(struct ost_body) == 168, " found %lld\n",
+        LASSERTF((int)sizeof(struct ost_body) == 172, " found %lld\n",
                  (long long)(int)sizeof(struct ost_body));
         LASSERTF(offsetof(struct ost_body, oa) == 0, " found %lld\n",
                  (long long)offsetof(struct ost_body, oa));
-        LASSERTF((int)sizeof(((struct ost_body *)0)->oa) == 168, " found %lld\n",
+        LASSERTF((int)sizeof(((struct ost_body *)0)->oa) == 172, " found %lld\n",
                  (long long)(int)sizeof(((struct ost_body *)0)->oa));
 
         /* Checks for struct ll_fid */
-        LASSERTF((int)sizeof(struct ll_fid) == 16, " found %lld\n",
+        LASSERTF((int)sizeof(struct ll_fid) == 24, " found %lld\n",
                  (long long)(int)sizeof(struct ll_fid));
         LASSERTF(offsetof(struct ll_fid, id) == 0, " found %lld\n",
                  (long long)offsetof(struct ll_fid, id));
@@ -1229,17 +1399,17 @@ void lustre_assert_wire_constants(void)
                  (long long)(int)sizeof(((struct mds_status_req *)0)->repbuf));
 
         /* Checks for struct mds_body */
-        LASSERTF((int)sizeof(struct mds_body) == 136, " found %lld\n",
+        LASSERTF((int)sizeof(struct mds_body) == 152, " found %lld\n",
                  (long long)(int)sizeof(struct mds_body));
         LASSERTF(offsetof(struct mds_body, fid1) == 0, " found %lld\n",
                  (long long)offsetof(struct mds_body, fid1));
-        LASSERTF((int)sizeof(((struct mds_body *)0)->fid1) == 16, " found %lld\n",
+        LASSERTF((int)sizeof(((struct mds_body *)0)->fid1) == 24, " found %lld\n",
                  (long long)(int)sizeof(((struct mds_body *)0)->fid1));
-        LASSERTF(offsetof(struct mds_body, fid2) == 16, " found %lld\n",
+        LASSERTF(offsetof(struct mds_body, fid2) == 24, " found %lld\n",
                  (long long)offsetof(struct mds_body, fid2));
-        LASSERTF((int)sizeof(((struct mds_body *)0)->fid2) == 16, " found %lld\n",
+        LASSERTF((int)sizeof(((struct mds_body *)0)->fid2) == 24, " found %lld\n",
                  (long long)(int)sizeof(((struct mds_body *)0)->fid2));
-        LASSERTF(offsetof(struct mds_body, handle) == 32, " found %lld\n",
+        LASSERTF(offsetof(struct mds_body, handle) == 48, " found %lld\n",
                  (long long)offsetof(struct mds_body, handle));
         LASSERTF((int)sizeof(((struct mds_body *)0)->handle) == 8, " found %lld\n",
                  (long long)(int)sizeof(((struct mds_body *)0)->handle));
@@ -2049,10 +2219,6 @@ void lustre_assert_wire_constants(void)
                  (long long)offsetof(struct llog_log_hdr, llh_tgtuuid));
         LASSERTF((int)sizeof(((struct llog_log_hdr *)0)->llh_tgtuuid) == 40, " found %lld\n",
                  (long long)(int)sizeof(((struct llog_log_hdr *)0)->llh_tgtuuid));
-        LASSERTF(offsetof(struct llog_log_hdr, llh_reserved) == 84, " found %lld\n",
-                 (long long)offsetof(struct llog_log_hdr, llh_reserved));
-        LASSERTF((int)sizeof(((struct llog_log_hdr *)0)->llh_reserved) == 4, " found %lld\n",
-                 (long long)(int)sizeof(((struct llog_log_hdr *)0)->llh_reserved));
         LASSERTF(offsetof(struct llog_log_hdr, llh_bitmap) == 88, " found %lld\n",
                  (long long)offsetof(struct llog_log_hdr, llh_bitmap));
         LASSERTF((int)sizeof(((struct llog_log_hdr *)0)->llh_bitmap) == 8096, " found %lld\n",
@@ -2109,8 +2275,8 @@ void lustre_assert_wire_constants(void)
                  (long long)offsetof(struct llogd_body, lgd_cur_offset));
         LASSERTF((int)sizeof(((struct llogd_body *)0)->lgd_cur_offset) == 8, " found %lld\n",
                  (long long)(int)sizeof(((struct llogd_body *)0)->lgd_cur_offset));
-        LASSERTF(LLOG_ORIGIN_HANDLE_CREATE == 501, " found %lld\n",
-                 (long long)LLOG_ORIGIN_HANDLE_CREATE);
+        LASSERTF(LLOG_ORIGIN_HANDLE_OPEN == 501, " found %lld\n",
+                 (long long)LLOG_ORIGIN_HANDLE_OPEN);
         LASSERTF(LLOG_ORIGIN_HANDLE_NEXT_BLOCK == 502, " found %lld\n",
                  (long long)LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
         LASSERTF(LLOG_ORIGIN_HANDLE_READ_HEADER == 503, " found %lld\n",
@@ -2139,5 +2305,6 @@ void lustre_assert_wire_constants(void)
                  (long long)offsetof(struct llogd_conn_body, lgdc_ctxt_idx));
         LASSERTF((int)sizeof(((struct llogd_conn_body *)0)->lgdc_ctxt_idx) == 4, " found %lld\n",
                  (long long)(int)sizeof(((struct llogd_conn_body *)0)->lgdc_ctxt_idx));
+#endif
 }