]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zfs_sa.c
cstyle: Resolve C style issues
[mirror_zfs.git] / module / zfs / zfs_sa.c
index ed696490fa0674ea8642a90ea95f4b8b3c5c6e3c..ebe92bb3a2ea6be1d2d6443ab0242be36271123b 100644 (file)
@@ -63,6 +63,7 @@ sa_attr_reg_t zfs_attr_table[ZPL_END+1] = {
        {"ZPL_SYMLINK", 0, SA_UINT8_ARRAY, 0},
        {"ZPL_SCANSTAMP", 32, SA_UINT8_ARRAY, 0},
        {"ZPL_DACL_ACES", 0, SA_ACL, 0},
+       {"ZPL_DXATTR", 0, SA_UINT8_ARRAY, 0},
        {NULL, 0, 0, 0}
 };
 
@@ -118,7 +119,6 @@ zfs_sa_symlink(znode_t *zp, char *link, int len, dmu_tx_t *tx)
        }
 }
 
-#ifdef HAVE_SCANSTAMP
 void
 zfs_sa_get_scanstamp(znode_t *zp, xvattr_t *xvap)
 {
@@ -183,12 +183,88 @@ zfs_sa_set_scanstamp(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
                    &zp->z_pflags, sizeof (uint64_t), tx));
        }
 }
-#endif /* HAVE_SCANSTAMP */
+
+int
+zfs_sa_get_xattr(znode_t *zp)
+{
+       zfs_sb_t *zsb = ZTOZSB(zp);
+       char *obj;
+       int size;
+       int error;
+
+       ASSERT(RW_LOCK_HELD(&zp->z_xattr_lock));
+       ASSERT(!zp->z_xattr_cached);
+       ASSERT(zp->z_is_sa);
+
+       error = sa_size(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), &size);
+       if (error) {
+               if (error == ENOENT)
+                       return nvlist_alloc(&zp->z_xattr_cached,
+                           NV_UNIQUE_NAME, KM_SLEEP);
+               else
+                       return (error);
+       }
+
+       obj = sa_spill_alloc(KM_SLEEP);
+
+       error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), obj, size);
+       if (error == 0)
+               error = nvlist_unpack(obj, size, &zp->z_xattr_cached, KM_SLEEP);
+
+       sa_spill_free(obj);
+
+       return (error);
+}
+
+int
+zfs_sa_set_xattr(znode_t *zp)
+{
+       zfs_sb_t *zsb = ZTOZSB(zp);
+       dmu_tx_t *tx;
+       char *obj;
+       size_t size;
+       int error;
+
+       ASSERT(RW_WRITE_HELD(&zp->z_xattr_lock));
+       ASSERT(zp->z_xattr_cached);
+       ASSERT(zp->z_is_sa);
+
+       error = nvlist_size(zp->z_xattr_cached, &size, NV_ENCODE_XDR);
+       if (error)
+               goto out;
+
+       obj = sa_spill_alloc(KM_SLEEP);
+
+       error = nvlist_pack(zp->z_xattr_cached, &obj, &size,
+           NV_ENCODE_XDR, KM_SLEEP);
+       if (error)
+               goto out_free;
+
+       tx = dmu_tx_create(zsb->z_os);
+       dmu_tx_hold_sa_create(tx, size);
+       dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
+
+       error = dmu_tx_assign(tx, TXG_WAIT);
+       if (error) {
+               dmu_tx_abort(tx);
+       } else {
+               error = sa_update(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb),
+                   obj, size, tx);
+               if (error)
+                       dmu_tx_abort(tx);
+               else
+                       dmu_tx_commit(tx);
+       }
+out_free:
+       sa_spill_free(obj);
+out:
+       return (error);
+}
 
 /*
  * I'm not convinced we should do any of this upgrade.
  * since the SA code can read both old/new znode formats
- * with probably little to know performance difference.
+ * with probably little to no performance difference.
  *
  * All new files will be created with the new format.
  */
@@ -205,9 +281,7 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
        uint64_t uid, gid, mode, rdev, xattr, parent;
        uint64_t crtime[2], mtime[2], ctime[2];
        zfs_acl_phys_t znode_acl;
-#ifdef HAVE_SCANSTAMP
        char scanstamp[AV_SCANSTAMP_SZ];
-#endif /* HAVE_SCANSTAMP */
        boolean_t drop_lock = B_FALSE;
 
        /*
@@ -236,7 +310,7 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
        }
 
        /* First do a bulk query of the attributes that aren't cached */
-       bulk = kmem_alloc(sizeof(sa_bulk_attr_t) * 20, KM_SLEEP);
+       bulk = kmem_alloc(sizeof (sa_bulk_attr_t) * 20, KM_SLEEP);
        SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL, &mtime, 16);
        SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL, &ctime, 16);
        SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zsb), NULL, &crtime, 16);
@@ -250,7 +324,7 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
            &znode_acl, 88);
 
        if (sa_bulk_lookup_locked(hdl, bulk, count) != 0) {
-               kmem_free(bulk, sizeof(sa_bulk_attr_t) * 20);
+               kmem_free(bulk, sizeof (sa_bulk_attr_t) * 20);
                goto done;
        }
 
@@ -259,7 +333,7 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
         * it is such a way to pick up an already existing layout number
         */
        count = 0;
-       sa_attrs = kmem_zalloc(sizeof(sa_bulk_attr_t) * 20, KM_SLEEP);
+       sa_attrs = kmem_zalloc(sizeof (sa_bulk_attr_t) * 20, KM_SLEEP);
        SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_MODE(zsb), NULL, &mode, 8);
        SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_SIZE(zsb), NULL,
            &zp->z_size, 8);
@@ -298,7 +372,6 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
                SA_ADD_BULK_ATTR(sa_attrs, count, SA_ZPL_XATTR(zsb),
                    NULL, &xattr, 8);
 
-#ifdef HAVE_SCANSTAMP
        /* if scanstamp then add scanstamp */
 
        if (zp->z_pflags & ZFS_BONUS_SCANSTAMP) {
@@ -308,7 +381,6 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
                    NULL, scanstamp, AV_SCANSTAMP_SZ);
                zp->z_pflags &= ~ZFS_BONUS_SCANSTAMP;
        }
-#endif /* HAVE_SCANSTAMP */
 
        VERIFY(dmu_set_bonustype(db, DMU_OT_SA, tx) == 0);
        VERIFY(sa_replace_all_by_template_locked(hdl, sa_attrs,
@@ -318,8 +390,8 @@ zfs_sa_upgrade(sa_handle_t *hdl, dmu_tx_t *tx)
                    znode_acl.z_acl_extern_obj, tx));
 
        zp->z_is_sa = B_TRUE;
-       kmem_free(sa_attrs, sizeof(sa_bulk_attr_t) * 20);
-       kmem_free(bulk, sizeof(sa_bulk_attr_t) * 20);
+       kmem_free(sa_attrs, sizeof (sa_bulk_attr_t) * 20);
+       kmem_free(bulk, sizeof (sa_bulk_attr_t) * 20);
 done:
        if (drop_lock)
                mutex_exit(&zp->z_lock);
@@ -340,4 +412,14 @@ zfs_sa_upgrade_txholds(dmu_tx_t *tx, znode_t *zp)
        }
 }
 
+EXPORT_SYMBOL(zfs_attr_table);
+EXPORT_SYMBOL(zfs_sa_readlink);
+EXPORT_SYMBOL(zfs_sa_symlink);
+EXPORT_SYMBOL(zfs_sa_get_scanstamp);
+EXPORT_SYMBOL(zfs_sa_set_scanstamp);
+EXPORT_SYMBOL(zfs_sa_get_xattr);
+EXPORT_SYMBOL(zfs_sa_set_xattr);
+EXPORT_SYMBOL(zfs_sa_upgrade);
+EXPORT_SYMBOL(zfs_sa_upgrade_txholds);
+
 #endif