Whamcloud - gitweb
LU-5262 osd: only allow set size for regular file
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index d640e72..730671a 100644 (file)
@@ -286,7 +286,7 @@ struct lu_object *osd_object_alloc(const struct lu_env *env,
 {
        struct osd_object *mo;
 
-       OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, __GFP_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, GFP_NOFS);
        if (mo != NULL) {
                struct lu_object *l;
 
@@ -339,7 +339,7 @@ int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
         */
        obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
 
-       cfs_mb();
+       smp_mb();
        obj->oo_dt.do_lu.lo_header->loh_attr |= LOHA_EXISTS;
 
        RETURN(0);
@@ -933,6 +933,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
        struct osd_thandle      *oh;
        struct osa_attr         *osa = &osd_oti_get(env)->oti_osa;
        sa_bulk_attr_t          *bulk;
+       __u64                    valid = la->la_valid;
        int                      cnt;
        int                      rc = 0;
 
@@ -947,7 +948,11 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
           transaction group. */
        LASSERT(oh->ot_tx->tx_txg != 0);
 
-       if (la->la_valid == 0)
+       /* Only allow set size for regular file */
+       if (!S_ISREG(dt->do_lu.lo_header->loh_attr))
+               valid &= ~(LA_SIZE | LA_BLOCKS);
+
+       if (valid == 0)
                RETURN(0);
 
        OBD_ALLOC(bulk, sizeof(sa_bulk_attr_t) * 10);
@@ -955,7 +960,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                RETURN(-ENOMEM);
 
        /* do both accounting updates outside oo_attr_lock below */
-       if ((la->la_valid & LA_UID) && (la->la_uid != obj->oo_attr.la_uid)) {
+       if ((valid & LA_UID) && (la->la_uid != obj->oo_attr.la_uid)) {
                /* Update user accounting. Failure isn't fatal, but we still
                 * log an error message */
                rc = -zap_increment_int(osd->od_objset.os, osd->od_iusr_oid,
@@ -970,7 +975,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                                "%d (%d)\n", osd->od_svname,
                                obj->oo_attr.la_uid, rc);
        }
-       if ((la->la_valid & LA_GID) && (la->la_gid != obj->oo_attr.la_gid)) {
+       if ((valid & LA_GID) && (la->la_gid != obj->oo_attr.la_gid)) {
                /* Update group accounting. Failure isn't fatal, but we still
                 * log an error message */
                rc = -zap_increment_int(osd->od_objset.os, osd->od_igrp_oid,
@@ -988,22 +993,22 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
 
        write_lock(&obj->oo_attr_lock);
        cnt = 0;
-       if (la->la_valid & LA_ATIME) {
+       if (valid & LA_ATIME) {
                osa->atime[0] = obj->oo_attr.la_atime = la->la_atime;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(uos), NULL,
                                 osa->atime, 16);
        }
-       if (la->la_valid & LA_MTIME) {
+       if (valid & LA_MTIME) {
                osa->mtime[0] = obj->oo_attr.la_mtime = la->la_mtime;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(uos), NULL,
                                 osa->mtime, 16);
        }
-       if (la->la_valid & LA_CTIME) {
+       if (valid & LA_CTIME) {
                osa->ctime[0] = obj->oo_attr.la_ctime = la->la_ctime;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(uos), NULL,
                                 osa->ctime, 16);
        }
-       if (la->la_valid & LA_MODE) {
+       if (valid & LA_MODE) {
                /* mode is stored along with type, so read it first */
                obj->oo_attr.la_mode = (obj->oo_attr.la_mode & S_IFMT) |
                        (la->la_mode & ~S_IFMT);
@@ -1011,22 +1016,22 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(uos), NULL,
                                 &osa->mode, 8);
        }
-       if (la->la_valid & LA_SIZE) {
+       if (valid & LA_SIZE) {
                osa->size = obj->oo_attr.la_size = la->la_size;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(uos), NULL,
                                 &osa->size, 8);
        }
-       if (la->la_valid & LA_NLINK) {
+       if (valid & LA_NLINK) {
                osa->nlink = obj->oo_attr.la_nlink = la->la_nlink;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(uos), NULL,
                                 &osa->nlink, 8);
        }
-       if (la->la_valid & LA_RDEV) {
+       if (valid & LA_RDEV) {
                osa->rdev = obj->oo_attr.la_rdev = la->la_rdev;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(uos), NULL,
                                 &osa->rdev, 8);
        }
-       if (la->la_valid & LA_FLAGS) {
+       if (valid & LA_FLAGS) {
                osa->flags = attrs_fs2zfs(la->la_flags);
                /* many flags are not supported by zfs, so ensure a good cached
                 * copy */
@@ -1034,17 +1039,17 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL,
                                 &osa->flags, 8);
        }
-       if (la->la_valid & LA_UID) {
+       if (valid & LA_UID) {
                osa->uid = obj->oo_attr.la_uid = la->la_uid;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_UID(uos), NULL,
                                 &osa->uid, 8);
        }
-       if (la->la_valid & LA_GID) {
+       if (valid & LA_GID) {
                osa->gid = obj->oo_attr.la_gid = la->la_gid;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_GID(uos), NULL,
                                 &osa->gid, 8);
        }
-       obj->oo_attr.la_valid |= la->la_valid;
+       obj->oo_attr.la_valid |= valid;
        write_unlock(&obj->oo_attr_lock);
 
        rc = osd_object_sa_bulk_update(obj, bulk, cnt, oh);
@@ -1226,10 +1231,6 @@ int __osd_object_create(const struct lu_env *env, udmu_objset_t *uos,
        int      rc;
 
        LASSERT(tag);
-       spin_lock(&uos->lock);
-       uos->objects++;
-       spin_unlock(&uos->lock);
-
        /* Assert that the transaction has been assigned to a
           transaction group. */
        LASSERT(tx->tx_txg != 0);
@@ -1238,14 +1239,24 @@ int __osd_object_create(const struct lu_env *env, udmu_objset_t *uos,
        oid = dmu_object_alloc(uos->os, DMU_OT_PLAIN_FILE_CONTENTS, 0,
                               DMU_OT_SA, DN_MAX_BONUSLEN, tx);
        rc = -sa_buf_hold(uos->os, oid, tag, dbp);
-       if (rc)
-               return rc;
+       LASSERTF(rc == 0, "sa_buf_hold "LPU64" failed: %d\n", oid, rc);
 
        LASSERT(la->la_valid & LA_MODE);
        la->la_size = 0;
        la->la_nlink = 1;
 
-       return __osd_attr_init(env, uos, oid, tx, la, parent);
+       rc = __osd_attr_init(env, uos, oid, tx, la, parent);
+       if (rc != 0) {
+               sa_buf_rele(*dbp, tag);
+               *dbp = NULL;
+               dmu_object_free(uos->os, oid, tx);
+               return rc;
+       }
+
+       spin_lock(&uos->lock);
+       uos->objects++;
+       spin_unlock(&uos->lock);
+       return 0;
 }
 
 /*
@@ -1491,7 +1502,7 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
 
        db = osd_create_type_f(dof->dof_type)(env, osd, attr, zapid, oh);
        if (IS_ERR(db))
-               GOTO(out, rc = PTR_ERR(th));
+               GOTO(out, rc = PTR_ERR(db));
 
        zde->zde_pad = 0;
        zde->zde_dnode = db->db_object;
@@ -1751,13 +1762,16 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env,
        RETURN(oc);
 }
 
-static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
+static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
+                          __u64 start, __u64 end)
 {
        struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
        ENTRY;
 
        /* XXX: no other option than syncing the whole filesystem until we
-        * support ZIL */
+        * support ZIL.  If the object tracked the txg that it was last
+        * modified in, it could pass that txg here instead of "0".  Maybe
+        * the changes are already committed, so no wait is needed at all? */
        txg_wait_synced(dmu_objset_pool(osd->od_objset.os), 0ULL);
 
        RETURN(0);