-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This patch adds a new class of system atributes which are referred to as "Native SA xattrs". The facilities described here are only enabled when "xattr=sa" is set. If xattr=sa is set, the following "security." and "system." xattrs are stored as native SA xattrs rather than as elements of the ZPL_DXATTR SA: xattr System atrribute -------------------------------------------------------- security.selinux ZPL_SECURITY_SELINUX security.capability ZPL_SECURITY_CAPABILITY system.posix_acl_access ZPL_SYSTEM_POSIX_ACL_ACCESS system.posix_acl_default ZPL_SYSTEM_POSIX_ACL_DEFAULT Storing these xattrs as native system attributes allows for the ZPL to more easily and naturally operate on them as an atomic part of other operations and will be used as the foundation for fixing issue openzfs#2718. Zdb will display these under the new "Native SA xattrs" section. Lookups of these xattrs will use the following priority: 1. Native SA xattr (as shown in the able above) 2. Linux ZPL_DXATTR nvlist 3. Traditional ZFS directory-style xattr Modifications of these xattrs will erase an existing ZPL_DXATTR instance of an identically-named xattrs but will not change an existing instance of an identically-named directory-style xattr. If a modification of the ZPL_DXATTR SA causes it to become empty, the ZPL_DXATTR SA, itself is deleted to maximize available space in the bonus buffer. The effect is that existing ZPL_DXATTR SAs are automatically upgraded as they are changed.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ sa_attr_reg_t zfs_attr_table[ZPL_END+1] = { | |
{"ZPL_SCANSTAMP", 32, SA_UINT8_ARRAY, 0}, | ||
{"ZPL_DACL_ACES", 0, SA_ACL, 0}, | ||
{"ZPL_DXATTR", 0, SA_UINT8_ARRAY, 0}, | ||
{"ZPL_SECURITY_SELINUX", 0, SA_UINT8_ARRAY, 0}, | ||
{"ZPL_SECURITY_CAPABILITY", 0, SA_UINT8_ARRAY, 0}, | ||
{"ZPL_SYSTEM_POSIX_ACL_ACCESS", 0, SA_UINT8_ARRAY, 0}, | ||
{"ZPL_SYSTEM_POSIX_ACL_DEFAULT", 0, SA_UINT8_ARRAY, 0}, | ||
{NULL, 0, 0, 0} | ||
}; | ||
|
||
|
@@ -248,8 +252,11 @@ zfs_sa_set_xattr(znode_t *zp) | |
if (error) { | ||
dmu_tx_abort(tx); | ||
} else { | ||
error = sa_update(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), | ||
obj, size, tx); | ||
if (nvlist_next_nvpair(zp->z_xattr_cached, NULL)) | ||
error = sa_update(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), | ||
obj, size, tx); | ||
else | ||
error = sa_remove(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), tx); | ||
if (error) | ||
dmu_tx_abort(tx); | ||
else | ||
|
@@ -261,6 +268,169 @@ zfs_sa_set_xattr(znode_t *zp) | |
return (error); | ||
} | ||
|
||
static void | ||
zfs_sa_remove_xattr(znode_t *zp, zpl_attr_t attr, int dxsize, dmu_tx_t *tx) | ||
{ | ||
extern const char *zpl_native_xattr_to_name(zpl_attr_t); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
zfs_sb_t *zsb = ZTOZSB(zp); | ||
const char *name; | ||
char *obj; | ||
int error = 0; | ||
|
||
/* | ||
* Look up the name of the native SA xattr. | ||
*/ | ||
name = zpl_native_xattr_to_name(attr); | ||
if (name == NULL) | ||
return; | ||
|
||
/* | ||
* Get the ZPL_DXATTR xattr if it's not cached. | ||
*/ | ||
if (zp->z_xattr_cached == NULL) { | ||
error = nvlist_alloc(&zp->z_xattr_cached, | ||
NV_UNIQUE_NAME, KM_SLEEP); | ||
if (error) | ||
return; | ||
obj = sa_spill_alloc(KM_SLEEP); | ||
error = sa_lookup(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), | ||
obj, dxsize); | ||
if (!error) | ||
error = nvlist_unpack(obj, dxsize, | ||
&zp->z_xattr_cached, KM_SLEEP); | ||
sa_spill_free(obj); | ||
} | ||
if (error || zp->z_xattr_cached == NULL) | ||
return; | ||
|
||
/* | ||
* Try to remove it. | ||
*/ | ||
error = nvlist_remove(zp->z_xattr_cached, name, DATA_TYPE_BYTE_ARRAY); | ||
if (error) | ||
return; | ||
|
||
/* | ||
* Remove the ZPL_DXATTR SA if it's empty, otherwise update it | ||
* to remove this xattr. | ||
*/ | ||
if (nvlist_next_nvpair(zp->z_xattr_cached, NULL)) { | ||
char *obj; | ||
size_t size; | ||
|
||
error = nvlist_size(zp->z_xattr_cached, &size, NV_ENCODE_XDR); | ||
if (error) | ||
return; | ||
|
||
obj = sa_spill_alloc(KM_SLEEP); | ||
|
||
error = nvlist_pack(zp->z_xattr_cached, &obj, &size, | ||
NV_ENCODE_XDR, KM_SLEEP); | ||
if (error) { | ||
sa_spill_free(obj); | ||
return; | ||
} | ||
|
||
(void) sa_update(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), | ||
obj, size, tx); | ||
|
||
sa_spill_free(obj); | ||
} else { | ||
(void) sa_remove(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), tx); | ||
} | ||
} | ||
|
||
int | ||
zfs_sa_native_set_xattr(znode_t *zp, zpl_attr_t attr, | ||
const void *value, size_t size, dmu_tx_t *tx) | ||
{ | ||
zfs_sb_t *zsb = ZTOZSB(zp); | ||
int error, dxsize; | ||
void *obj = NULL; | ||
boolean_t havetx = B_FALSE; | ||
|
||
ASSERT(RW_WRITE_HELD(&zp->z_xattr_lock)); | ||
ASSERT(zp->z_is_sa); | ||
|
||
/* | ||
* Temporary copy of otherwise read-only value to | ||
* satisfy the non-const API of the lower-level SA | ||
* functions. | ||
*/ | ||
if (value) { | ||
obj = sa_spill_alloc(KM_SLEEP); | ||
bcopy(value, obj, size); | ||
} | ||
|
||
if (tx) | ||
havetx = B_TRUE; | ||
else | ||
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); | ||
|
||
if (!havetx) { | ||
error = dmu_tx_assign(tx, TXG_WAIT); | ||
if (error) { | ||
dmu_tx_abort(tx); | ||
goto out; | ||
} | ||
} | ||
|
||
/* | ||
* Remove an identical instance of this xattr from the ZPL_DXATTR SA. | ||
*/ | ||
if (sa_size(zp->z_sa_hdl, SA_ZPL_DXATTR(zsb), &dxsize) == 0) | ||
zfs_sa_remove_xattr(zp, attr, dxsize, tx); | ||
|
||
/* | ||
* Remove or update the native SA xattr. | ||
*/ | ||
if (value) | ||
error = sa_update(zp->z_sa_hdl, zsb->z_attr_table[attr], | ||
obj, size, tx); | ||
else { | ||
error = sa_remove(zp->z_sa_hdl, zsb->z_attr_table[attr], tx); | ||
} | ||
|
||
if (!havetx) { | ||
if (error) | ||
dmu_tx_abort(tx); | ||
else | ||
dmu_tx_commit(tx); | ||
} | ||
out: | ||
if (value) | ||
sa_spill_free(obj); | ||
return (error); | ||
} | ||
|
||
int | ||
zfs_sa_native_get_xattr(znode_t *zp, zpl_attr_t attr, void *value, size_t size) | ||
This comment has been minimized.
Sorry, something went wrong.
behlendorf
|
||
{ | ||
zfs_sb_t *zsb = ZTOZSB(zp); | ||
int attr_size; | ||
int error; | ||
|
||
ASSERT(RW_LOCK_HELD(&zp->z_xattr_lock)); | ||
ASSERT(zp->z_is_sa); | ||
|
||
error = sa_size(zp->z_sa_hdl, zsb->z_attr_table[attr], &attr_size); | ||
if (error) | ||
return (-error); | ||
if (!size) | ||
return (attr_size); | ||
if (size < attr_size) | ||
return (-ERANGE); | ||
error = sa_lookup(zp->z_sa_hdl, zsb->z_attr_table[attr], | ||
value, attr_size); | ||
if (error) | ||
return (-error); | ||
return (attr_size); | ||
} | ||
|
||
|
||
/* | ||
* I'm not convinced we should do any of this upgrade. | ||
* since the SA code can read both old/new znode formats | ||
|
@@ -416,6 +586,8 @@ 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_native_set_xattr); | ||
EXPORT_SYMBOL(zfs_sa_native_get_xattr); | ||
EXPORT_SYMBOL(zfs_sa_set_scanstamp); | ||
EXPORT_SYMBOL(zfs_sa_get_xattr); | ||
EXPORT_SYMBOL(zfs_sa_set_xattr); | ||
|
Declaring an extern function here is asking for trouble. It would be better to either pass the
zpl_xattr_sa_t
so you have the name and can avoid the lookup. Or properly declare the function in an included header. There is a bit of a layering violation here which should be sorted out.