Whamcloud - gitweb
LU-11303 out: clean up osp_update_rpc_pack() macro 07/33107/3
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 4 Sep 2018 09:50:48 +0000 (17:50 +0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 21 Sep 2018 03:30:47 +0000 (03:30 +0000)
The osp_update_rpc_pack() macro was using both an operation "name"
argument as well as an "opcode" argument, but totally ignoring the
"opcode" argument.  This allowed a caller in osp_attr_set() to pass
a non-existent opcode name to the function that was ignored.

The function also concatenated the passed name string to generate
a function name to be called (which supplied its own opcode value).
This name concatenation obscures the code functionality, since the
called functions are not actually referenced directly in the code.

Instead, pass the function name as the argument, and drop the opcode
completely.  This at least makes it possible to see where the function
is being called.  Change the macro to be upper-case, so that it is
more clear that it is a macro rather than a real function.  It would
be better to replace the macro with an actual function, but this is
not very practical due to the use of variable-length argument lists.

Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I7bf5c1d0f7a9abab1d8de8046cc408961f3ebbe5
Reviewed-on: https://review.whamcloud.com/33107
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-by: Hongchao Zhang <hongchao@whamcloud.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/osp/osp_internal.h
lustre/osp/osp_md_object.c
lustre/osp/osp_object.c

index 711a787..ce8734c 100644 (file)
@@ -622,10 +622,10 @@ osp_current_object_update_request(struct osp_update_request *our);
 int osp_object_update_request_create(struct osp_update_request *our,
                                     size_t size);
 
 int osp_object_update_request_create(struct osp_update_request *our,
                                     size_t size);
 
-#define osp_update_rpc_pack(env, name, our, op, ...)                   \
+#define OSP_UPDATE_RPC_PACK(env, out_something_pack, our, ...)         \
 ({                                                                     \
 ({                                                                     \
-       struct object_update    *object_update;                         \
-       size_t                  max_update_length;                      \
+       struct object_update *object_update;                            \
+       size_t max_update_length;                                       \
        struct osp_update_request_sub *ours;                            \
        int ret;                                                        \
                                                                        \
        struct osp_update_request_sub *ours;                            \
        int ret;                                                        \
                                                                        \
@@ -637,9 +637,9 @@ int osp_object_update_request_create(struct osp_update_request *our,
                                                                        \
                object_update = update_buffer_get_update(ours->ours_req,\
                                         ours->ours_req->ourq_count);   \
                                                                        \
                object_update = update_buffer_get_update(ours->ours_req,\
                                         ours->ours_req->ourq_count);   \
-               ret = out_##name##_pack(env, object_update,             \
-                                       &max_update_length,             \
-                                      __VA_ARGS__);                    \
+               ret = out_something_pack(env, object_update,            \
+                                        &max_update_length,            \
+                                        __VA_ARGS__);                  \
                if (ret == -E2BIG) {                                    \
                        int rc1;                                        \
                        /* Create new object update request */          \
                if (ret == -E2BIG) {                                    \
                        int rc1;                                        \
                        /* Create new object update request */          \
index 7acbc51..b66509a 100644 (file)
@@ -157,15 +157,15 @@ int osp_md_create(const struct lu_env *env, struct dt_object *dt,
                  struct lu_attr *attr, struct dt_allocation_hint *hint,
                  struct dt_object_format *dof, struct thandle *th)
 {
                  struct lu_attr *attr, struct dt_allocation_hint *hint,
                  struct dt_object_format *dof, struct thandle *th)
 {
-       struct osp_update_request       *update;
-       struct osp_object               *obj = dt2osp_obj(dt);
-       int                             rc;
+       struct osp_update_request *update;
+       struct osp_object *obj = dt2osp_obj(dt);
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
        LASSERT(attr->la_valid & LA_TYPE);
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
        LASSERT(attr->la_valid & LA_TYPE);
-       rc = osp_update_rpc_pack(env, create, update, OUT_CREATE,
+       rc = OSP_UPDATE_RPC_PACK(env, out_create_pack, update,
                                 lu_object_fid(&dt->do_lu), attr, hint, dof);
        if (rc != 0)
                GOTO(out, rc);
                                 lu_object_fid(&dt->do_lu), attr, hint, dof);
        if (rc != 0)
                GOTO(out, rc);
@@ -219,13 +219,13 @@ static int osp_md_declare_ref_del(const struct lu_env *env,
 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
                          struct thandle *th)
 {
 static int osp_md_ref_del(const struct lu_env *env, struct dt_object *dt,
                          struct thandle *th)
 {
-       struct osp_update_request       *update;
-       int                             rc;
+       struct osp_update_request *update;
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, ref_del, update, OUT_REF_DEL,
+       rc = OSP_UPDATE_RPC_PACK(env, out_ref_del_pack, update,
                                 lu_object_fid(&dt->do_lu));
        return rc;
 }
                                 lu_object_fid(&dt->do_lu));
        return rc;
 }
@@ -265,13 +265,13 @@ static int osp_md_declare_ref_add(const struct lu_env *env,
 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
                          struct thandle *th)
 {
 static int osp_md_ref_add(const struct lu_env *env, struct dt_object *dt,
                          struct thandle *th)
 {
-       struct osp_update_request       *update;
-       int                             rc;
+       struct osp_update_request *update;
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, ref_add, update, OUT_REF_ADD,
+       rc = OSP_UPDATE_RPC_PACK(env, out_ref_add_pack, update,
                                 lu_object_fid(&dt->do_lu));
        return rc;
 }
                                 lu_object_fid(&dt->do_lu));
        return rc;
 }
@@ -341,13 +341,13 @@ int osp_md_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
                    const struct lu_attr *attr, struct thandle *th)
 {
 int osp_md_attr_set(const struct lu_env *env, struct dt_object *dt,
                    const struct lu_attr *attr, struct thandle *th)
 {
-       struct osp_update_request       *update;
-       int                             rc;
+       struct osp_update_request *update;
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, attr_set, update, OUT_ATTR_SET,
+       rc = OSP_UPDATE_RPC_PACK(env, out_attr_set_pack, update,
                                 lu_object_fid(&dt->do_lu), attr);
        return rc;
 }
                                 lu_object_fid(&dt->do_lu), attr);
        return rc;
 }
@@ -477,7 +477,7 @@ static int osp_md_index_lookup(const struct lu_env *env, struct dt_object *dt,
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = osp_update_rpc_pack(env, index_lookup, update, OUT_INDEX_LOOKUP,
+       rc = OSP_UPDATE_RPC_PACK(env, out_index_lookup_pack, update,
                                 lu_object_fid(&dt->do_lu), rec, key);
        if (rc != 0) {
                CERROR("%s: Insert update error: rc = %d\n",
                                 lu_object_fid(&dt->do_lu), rec, key);
        if (rc != 0) {
                CERROR("%s: Insert update error: rc = %d\n",
@@ -574,20 +574,18 @@ static int osp_md_declare_index_insert(const struct lu_env *env,
  * \retval             0 if packing index insert succeeds.
  * \retval             negative errno if packing fails.
  */
  * \retval             0 if packing index insert succeeds.
  * \retval             negative errno if packing fails.
  */
-static int osp_md_index_insert(const struct lu_env *env,
-                              struct dt_object *dt,
+static int osp_md_index_insert(const struct lu_env *env, struct dt_object *dt,
                               const struct dt_rec *rec,
                               const struct dt_rec *rec,
-                              const struct dt_key *key,
-                              struct thandle *th,
+                              const struct dt_key *key, struct thandle *th,
                               int ignore_quota)
 {
        struct osp_update_request *update;
                               int ignore_quota)
 {
        struct osp_update_request *update;
-       int                      rc;
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, index_insert, update, OUT_INDEX_INSERT,
+       rc = OSP_UPDATE_RPC_PACK(env, out_index_insert_pack, update,
                                 lu_object_fid(&dt->do_lu), rec, key);
        return rc;
 }
                                 lu_object_fid(&dt->do_lu), rec, key);
        return rc;
 }
@@ -639,7 +637,7 @@ static int osp_md_index_delete(const struct lu_env *env,
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, index_delete, update, OUT_INDEX_DELETE,
+       rc = OSP_UPDATE_RPC_PACK(env, out_index_delete_pack, update,
                                 lu_object_fid(&dt->do_lu), key);
 
        return rc;
                                 lu_object_fid(&dt->do_lu), key);
 
        return rc;
@@ -854,7 +852,7 @@ static int osp_md_xattr_list(const struct lu_env *env, struct dt_object *dt,
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = osp_update_rpc_pack(env, xattr_list, update, OUT_XATTR_LIST,
+       rc = OSP_UPDATE_RPC_PACK(env, out_xattr_list_pack, update,
                                 lu_object_fid(&dt->do_lu), buf->lb_len);
        if (rc) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                                 lu_object_fid(&dt->do_lu), buf->lb_len);
        if (rc) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
@@ -1040,10 +1038,10 @@ int osp_md_declare_destroy(const struct lu_env *env, struct dt_object *dt,
 int osp_md_destroy(const struct lu_env *env, struct dt_object *dt,
                   struct thandle *th)
 {
 int osp_md_destroy(const struct lu_env *env, struct dt_object *dt,
                   struct thandle *th)
 {
-       struct osp_object               *o = dt2osp_obj(dt);
-       struct osp_device               *osp = lu2osp_dev(dt->do_lu.lo_dev);
-       struct osp_update_request       *update;
-       int                             rc = 0;
+       struct osp_object *o = dt2osp_obj(dt);
+       struct osp_device *osp = lu2osp_dev(dt->do_lu.lo_dev);
+       struct osp_update_request *update;
+       int rc = 0;
 
        ENTRY;
        o->opo_non_exist = 1;
 
        ENTRY;
        o->opo_non_exist = 1;
@@ -1052,7 +1050,7 @@ int osp_md_destroy(const struct lu_env *env, struct dt_object *dt,
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, destroy, update, OUT_DESTROY,
+       rc = OSP_UPDATE_RPC_PACK(env, out_destroy_pack, update,
                                 lu_object_fid(&dt->do_lu));
        if (rc != 0)
                RETURN(rc);
                                 lu_object_fid(&dt->do_lu));
        if (rc != 0)
                RETURN(rc);
@@ -1162,7 +1160,7 @@ static ssize_t osp_md_write(const struct lu_env *env, struct dt_object *dt,
        CDEBUG(D_INFO, "write "DFID" offset = %llu length = %zu\n",
               PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
 
        CDEBUG(D_INFO, "write "DFID" offset = %llu length = %zu\n",
               PFID(lu_object_fid(&dt->do_lu)), *pos, buf->lb_len);
 
-       rc = osp_update_rpc_pack(env, write, update, OUT_WRITE,
+       rc = OSP_UPDATE_RPC_PACK(env, out_write_pack, update,
                                 lu_object_fid(&dt->do_lu), buf, *pos);
        if (rc < 0)
                RETURN(rc);
                                 lu_object_fid(&dt->do_lu), buf, *pos);
        if (rc < 0)
                RETURN(rc);
@@ -1224,7 +1222,7 @@ static ssize_t osp_md_read(const struct lu_env *env, struct dt_object *dt,
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = osp_update_rpc_pack(env, read, update, OUT_READ,
+       rc = OSP_UPDATE_RPC_PACK(env, out_read_pack, update,
                                 lu_object_fid(&dt->do_lu),
                                 rbuf->lb_len, *pos);
        if (rc != 0) {
                                 lu_object_fid(&dt->do_lu),
                                 rbuf->lb_len, *pos);
        if (rc != 0) {
index f1a14fb..641aa65 100644 (file)
@@ -561,7 +561,7 @@ int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
        if (IS_ERR(update))
                RETURN(PTR_ERR(update));
 
-       rc = osp_update_rpc_pack(env, attr_get, update, OUT_ATTR_GET,
+       rc = OSP_UPDATE_RPC_PACK(env, out_attr_get_pack, update,
                                 lu_object_fid(&dt->do_lu));
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                                 lu_object_fid(&dt->do_lu));
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
@@ -718,8 +718,7 @@ static int osp_attr_set(const struct lu_env *env, struct dt_object *dt,
                        if (IS_ERR(update))
                                RETURN(PTR_ERR(update));
 
                        if (IS_ERR(update))
                                RETURN(PTR_ERR(update));
 
-                       rc = osp_update_rpc_pack(env, attr_set, update,
-                                                OUT_ASTTR_SET,
+                       rc = OSP_UPDATE_RPC_PACK(env, out_attr_set_pack, update,
                                                 lu_object_fid(&dt->do_lu),
                                                 attr);
                        if (rc != 0) {
                                                 lu_object_fid(&dt->do_lu),
                                                 attr);
                        if (rc != 0) {
@@ -989,7 +988,7 @@ unlock:
        if (IS_ERR(update))
                GOTO(out, rc = PTR_ERR(update));
 
        if (IS_ERR(update))
                GOTO(out, rc = PTR_ERR(update));
 
-       rc = osp_update_rpc_pack(env, xattr_get, update, OUT_XATTR_GET,
+       rc = OSP_UPDATE_RPC_PACK(env, out_xattr_get_pack, update,
                                 lu_object_fid(&dt->do_lu), name, buf->lb_len);
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
                                 lu_object_fid(&dt->do_lu), name, buf->lb_len);
        if (rc != 0) {
                CERROR("%s: Insert update error "DFID": rc = %d\n",
@@ -1159,10 +1158,10 @@ int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
                  const struct lu_buf *buf, const char *name, int fl,
                  struct thandle *th)
 {
                  const struct lu_buf *buf, const char *name, int fl,
                  struct thandle *th)
 {
-       struct osp_object       *o = dt2osp_obj(dt);
+       struct osp_object *o = dt2osp_obj(dt);
        struct osp_update_request *update;
        struct osp_update_request *update;
-       struct osp_xattr_entry  *oxe;
-       int                     rc;
+       struct osp_xattr_entry *oxe;
+       int rc;
        ENTRY;
 
        update = thandle_to_osp_update_request(th);
        ENTRY;
 
        update = thandle_to_osp_update_request(th);
@@ -1171,7 +1170,7 @@ int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
        CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
               PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
 
        CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
               PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
 
-       rc = osp_update_rpc_pack(env, xattr_set, update, OUT_XATTR_SET,
+       rc = OSP_UPDATE_RPC_PACK(env, out_xattr_set_pack, update,
                                 lu_object_fid(&dt->do_lu), buf, name, fl);
        if (rc != 0)
                RETURN(rc);
                                 lu_object_fid(&dt->do_lu), buf, name, fl);
        if (rc != 0)
                RETURN(rc);
@@ -1248,16 +1247,15 @@ int osp_xattr_del(const struct lu_env *env, struct dt_object *dt,
                  const char *name, struct thandle *th)
 {
        struct osp_update_request *update;
                  const char *name, struct thandle *th)
 {
        struct osp_update_request *update;
-       const struct lu_fid      *fid = lu_object_fid(&dt->do_lu);
-       struct osp_object        *o     = dt2osp_obj(dt);
-       struct osp_xattr_entry   *oxe;
-       int                       rc;
+       const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
+       struct osp_object *o = dt2osp_obj(dt);
+       struct osp_xattr_entry *oxe;
+       int rc;
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
 
        update = thandle_to_osp_update_request(th);
        LASSERT(update != NULL);
 
-       rc = osp_update_rpc_pack(env, xattr_del, update, OUT_XATTR_DEL,
-                                fid, name);
+       rc = OSP_UPDATE_RPC_PACK(env, out_xattr_del_pack, update, fid, name);
        if (rc != 0)
                return rc;
 
        if (rc != 0)
                return rc;