Whamcloud - gitweb
LU-6299 osp: zero-length EA xattr_set for striped_dir 87/14787/4
authorwang di <di.wang@intel.com>
Mon, 11 May 2015 16:38:02 +0000 (09:38 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 28 May 2015 17:06:27 +0000 (17:06 +0000)
OSP/OUT should not assume xattr values always have
non-zero length, and OSP should be able to pack empty
xattr updates and sends to OUT.

Add test case in sanity 102r to verify empty value
xattr_set for striped dir.

Signed-off-by: wang di <di.wang@intel.com>
Change-Id: I14e0172038ef4c5671ec470228edd7cc4533a89c
Reviewed-on: http://review.whamcloud.com/14787
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Lai Siyao <lai.siyao@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre_update.h
lustre/osp/osp_object.c
lustre/target/out_handler.c
lustre/tests/sanity.sh

index 3d941b9..1ba3e34 100644 (file)
@@ -88,7 +88,7 @@ static inline void
        size_t          i;
 
        if (index >= update->ou_params_count)
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        param = &update->ou_params[0];
        for (i = 0; i < index; i++)
index e838544..824564f 100644 (file)
@@ -1146,7 +1146,6 @@ int osp_xattr_set(const struct lu_env *env, struct dt_object *dt,
        int                     rc;
        ENTRY;
 
-       LASSERT(buf->lb_len > 0 && buf->lb_buf != NULL);
        update = thandle_to_dt_update_request(th);
        LASSERT(update != NULL);
 
index 972391f..7a4c554 100644 (file)
@@ -256,7 +256,7 @@ static int out_create(struct tgt_session_info *tsi)
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (wobdo == NULL || size != sizeof(*wobdo)) {
+       if (wobdo == NULL || IS_ERR(wobdo) || size != sizeof(*wobdo)) {
                CERROR("%s: obdo is NULL, invalid RPC: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -270,7 +270,7 @@ static int out_create(struct tgt_session_info *tsi)
        dof->dof_type = dt_mode_to_dft(attr->la_mode);
        if (update->ou_params_count > 1) {
                fid = object_update_param_get(update, 1, &size);
-               if (fid == NULL || size != sizeof(*fid)) {
+               if (fid == NULL || IS_ERR(fid) || size != sizeof(*fid)) {
                        CERROR("%s: invalid fid: rc = %d\n",
                               tgt_name(tsi->tsi_tgt), -EPROTO);
                        RETURN(err_serious(-EPROTO));
@@ -368,7 +368,7 @@ static int out_attr_set(struct tgt_session_info *tsi)
        ENTRY;
 
        wobdo = object_update_param_get(update, 0, &size);
-       if (wobdo == NULL || size != sizeof(*wobdo)) {
+       if (wobdo == NULL || IS_ERR(wobdo) || size != sizeof(*wobdo)) {
                CERROR("%s: empty obdo in the update: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -455,7 +455,7 @@ static int out_xattr_get(struct tgt_session_info *tsi)
        }
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for xattr get: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -511,7 +511,7 @@ static int out_index_lookup(struct tgt_session_info *tsi)
                RETURN(-ENOENT);
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for lookup: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -662,18 +662,15 @@ static int out_xattr_set(struct tgt_session_info *tsi)
        ENTRY;
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for xattr set: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
        }
 
        buf = object_update_param_get(update, 1, &buf_len);
-       if (buf == NULL || buf_len == 0) {
-               CERROR("%s: empty buf for xattr set: rc = %d\n",
-                      tgt_name(tsi->tsi_tgt), -EPROTO);
+       if (IS_ERR(buf))
                RETURN(err_serious(-EPROTO));
-       }
 
        lbuf->lb_buf = buf;
        lbuf->lb_len = buf_len;
@@ -756,7 +753,7 @@ static int out_xattr_del(struct tgt_session_info *tsi)
        ENTRY;
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for xattr set: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -1044,17 +1041,17 @@ static int out_index_insert(struct tgt_session_info *tsi)
        ENTRY;
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for index insert: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
        }
 
        fid = object_update_param_get(update, 1, &size);
-       if (fid == NULL || size != sizeof(*fid)) {
+       if (fid == NULL || IS_ERR(fid) || size != sizeof(*fid)) {
                CERROR("%s: invalid fid: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
-                      RETURN(err_serious(-EPROTO));
+               RETURN(err_serious(-EPROTO));
        }
 
        if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req))
@@ -1067,7 +1064,7 @@ static int out_index_insert(struct tgt_session_info *tsi)
        }
 
        ptype = object_update_param_get(update, 2, &size);
-       if (ptype == NULL || size != sizeof(*ptype)) {
+       if (ptype == NULL || IS_ERR(ptype) || size != sizeof(*ptype)) {
                CERROR("%s: invalid type for index insert: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -1156,7 +1153,7 @@ static int out_index_delete(struct tgt_session_info *tsi)
                RETURN(-ENOENT);
 
        name = object_update_param_get(update, 0, NULL);
-       if (name == NULL) {
+       if (name == NULL || IS_ERR(name)) {
                CERROR("%s: empty name for index delete: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -1306,7 +1303,7 @@ static int out_write(struct tgt_session_info *tsi)
        ENTRY;
 
        buf = object_update_param_get(update, 0, &buf_len);
-       if (buf == NULL || buf_len == 0) {
+       if (buf == NULL || IS_ERR(buf) || buf_len == 0) {
                CERROR("%s: empty buf for xattr set: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), -EPROTO);
                RETURN(err_serious(-EPROTO));
@@ -1315,7 +1312,7 @@ static int out_write(struct tgt_session_info *tsi)
        lbuf->lb_len = buf_len;
 
        tmp = object_update_param_get(update, 1, &size);
-       if (tmp == NULL || size != sizeof(*tmp)) {
+       if (tmp == NULL || IS_ERR(tmp) || size != sizeof(*tmp)) {
                CERROR("%s: empty or wrong size %zu pos: rc = %d\n",
                       tgt_name(tsi->tsi_tgt), size, -EPROTO);
                RETURN(err_serious(-EPROTO));
index 5ed33d8..3bd5dde 100644 (file)
@@ -6946,6 +6946,28 @@ test_102r() {
        setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
        getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
        rm $DIR/$tfile || error "rm"
+
+       #normal directory
+       mkdir -p $DIR/$tdir || error "mkdir"
+       setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
+       getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
+       setfattr -x user.$(basename $tdir) $DIR/$tdir ||
+               error "$testfile error deleting user.author1"
+       getfattr -d -m user.$(basename $tdir) 2> /dev/null |
+               grep "user.$(basename $tdir)" &&
+               error "$tdir did not delete user.$(basename $tdir)"
+       rmdir $DIR/$tdir || error "rmdir"
+
+       #striped directory
+       test_mkdir -p $DIR/$tdir || error "make striped dir"
+       setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
+       getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
+       setfattr -x user.$(basename $tdir) $DIR/$tdir ||
+               error "$testfile error deleting user.author1"
+       getfattr -d -m user.$(basename $tdir) 2> /dev/null |
+               grep "user.$(basename $tdir)" &&
+               error "$tdir did not delete user.$(basename $tdir)"
+       rmdir $DIR/$tdir || error "rm striped dir"
 }
 run_test 102r "set EAs with empty values"