/* * Shared xattr name/value buffers for logged extended attribute operations * * When logging updates to extended attributes, we can create quite a few * attribute log intent items for a single xattr update. To avoid cycling the * memory allocator and memcpy overhead, the name (and value, for setxattr) * are kept in a refcounted object that is shared across all related log items * and the upper-level deferred work state structure. The shared buffer has * a control structure, followed by the name, and then the value.
*/
/* * This could be over 64kB in length, so we have to use kvmalloc() for * this. But kvmalloc() utterly sucks, so we use our own version.
*/
nv = xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval) +
name_len + new_name_len + value_len +
new_value_len);
/* * Freeing the attrip requires that we remove it from the AIL if it has already * been placed there. However, the ATTRI may not yet have been placed in the * AIL when called by xfs_attri_release() from ATTRD processing due to the * ordering of committed vs unpin operations in bulk insert operations. Hence * the reference count to ensure only the last caller frees the ATTRI.
*/ STATICvoid
xfs_attri_release( struct xfs_attri_log_item *attrip)
{
ASSERT(atomic_read(&attrip->attri_refcount) > 0); if (!atomic_dec_and_test(&attrip->attri_refcount)) return;
/* * This is called to fill in the log iovecs for the given attri log * item. We use 1 iovec for the attri_format_item, 1 for the name, and * another for the value if it is present
*/ STATICvoid
xfs_attri_item_format( struct xfs_log_item *lip, struct xfs_log_vec *lv)
{ struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip); struct xfs_log_iovec *vecp = NULL; struct xfs_attri_log_nameval *nv = attrip->attri_nameval;
/* * This size accounting must be done before copying the attrip into the * iovec. If we do it after, the wrong size will be recorded to the log * and we trip across assertion checks for bad region sizes later during * the log recovery.
*/
if (nv->new_name.iov_len > 0)
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTR_NEWNAME,
nv->new_name.iov_base, nv->new_name.iov_len);
if (nv->value.iov_len > 0)
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTR_VALUE,
nv->value.iov_base, nv->value.iov_len);
if (nv->new_value.iov_len > 0)
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTR_NEWVALUE,
nv->new_value.iov_base, nv->new_value.iov_len);
}
/* * The unpin operation is the last place an ATTRI is manipulated in the log. It * is either inserted in the AIL or aborted in the event of a log I/O error. In * either case, the ATTRI transaction has been successfully committed to make * it this far. Therefore, we expect whoever committed the ATTRI to either * construct and commit the ATTRD or drop the ATTRD's reference in the event of * error. Simply drop the log's ATTRI reference now that the log is done with * it.
*/ STATICvoid
xfs_attri_item_unpin( struct xfs_log_item *lip, int remove)
{
xfs_attri_release(ATTRI_ITEM(lip));
}
/* * Allocate and initialize an attri item. Caller may allocate an additional * trailing buffer for name and value
*/ STATICstruct xfs_attri_log_item *
xfs_attri_init( struct xfs_mount *mp, struct xfs_attri_log_nameval *nv)
{ struct xfs_attri_log_item *attrip;
/* * Grab an extra reference to the name/value buffer for this log item. * The caller retains its own reference!
*/
attrip->attri_nameval = xfs_attri_log_nameval_get(nv);
ASSERT(attrip->attri_nameval);
STATICvoid
xfs_attrd_item_size( struct xfs_log_item *lip, int *nvecs, int *nbytes)
{
*nvecs += 1;
*nbytes += sizeof(struct xfs_attrd_log_format);
}
/* * This is called to fill in the log iovecs for the given attrd log item. We use * only 1 iovec for the attrd_format, and we point that at the attr_log_format * structure embedded in the attrd item.
*/ STATICvoid
xfs_attrd_item_format( struct xfs_log_item *lip, struct xfs_log_vec *lv)
{ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip); struct xfs_log_iovec *vecp = NULL;
/* * The ATTRD is either committed or aborted if the transaction is canceled. If * the transaction is canceled, drop our reference to the ATTRI and free the * ATTRD.
*/ STATICvoid
xfs_attrd_item_release( struct xfs_log_item *lip)
{ struct xfs_attrd_log_item *attrdp = ATTRD_ITEM(lip);
/* * At this point the xfs_attr_intent has been constructed, and we've * created the log intent. Fill in the attri log item and log format * structure with fields from this xfs_attr_intent
*/
attrp = &attrip->attri_format;
attrp->alfi_ino = args->dp->i_ino;
ASSERT(!(attr->xattri_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK));
attrp->alfi_op_flags = attr->xattri_op_flags;
attrp->alfi_value_len = nv->value.iov_len;
switch (xfs_attr_log_item_op(attrp)) { case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE:
ASSERT(nv->value.iov_len == nv->new_value.iov_len);
/* * Each attr item only performs one attribute operation at a time, so * this is a list of one
*/
attr = list_first_entry_or_null(items, struct xfs_attr_intent,
xattri_list);
args = attr->xattri_da_args;
if (!(args->op_flags & XFS_DA_OP_LOGGED)) return NULL;
/* * Create a buffer to store the attribute name and value. This buffer * will be shared between the higher level deferred xattr work state * and the lower level xattr log items.
*/ if (!attr->xattri_nameval) { /* * Transfer our reference to the name/value buffer to the * deferred work state structure.
*/
attr->xattri_nameval = xfs_attri_log_nameval_alloc(
args->name, args->namelen,
args->new_name, args->new_namelen,
args->value, args->valuelen,
args->new_value, args->new_valuelen);
}
/* Is this recovered ATTRI format ok? */ staticinlinebool
xfs_attri_validate( struct xfs_mount *mp, struct xfs_attri_log_format *attrp)
{ unsignedint op = xfs_attr_log_item_op(attrp);
if (attrp->alfi_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK) returnfalse;
if (attrp->alfi_attr_filter & ~XFS_ATTRI_FILTER_MASK) returnfalse;
if (!xfs_attr_check_namespace(attrp->alfi_attr_filter &
XFS_ATTR_NSP_ONDISK_MASK)) returnfalse;
switch (op) { case XFS_ATTRI_OP_FLAGS_PPTR_SET: case XFS_ATTRI_OP_FLAGS_PPTR_REMOVE: if (!xfs_has_parent(mp)) returnfalse; if (attrp->alfi_value_len != sizeof(struct xfs_parent_rec)) returnfalse; if (!xfs_attri_validate_namelen(attrp->alfi_name_len)) returnfalse; if (!(attrp->alfi_attr_filter & XFS_ATTR_PARENT)) returnfalse; break; case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE: if (!xfs_is_using_logged_xattrs(mp)) returnfalse; if (attrp->alfi_value_len > XATTR_SIZE_MAX) returnfalse; if (!xfs_attri_validate_namelen(attrp->alfi_name_len)) returnfalse; break; case XFS_ATTRI_OP_FLAGS_REMOVE: if (!xfs_is_using_logged_xattrs(mp)) returnfalse; if (attrp->alfi_value_len != 0) returnfalse; if (!xfs_attri_validate_namelen(attrp->alfi_name_len)) returnfalse; break; case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE: if (!xfs_has_parent(mp)) returnfalse; if (!xfs_attri_validate_namelen(attrp->alfi_old_name_len)) returnfalse; if (!xfs_attri_validate_namelen(attrp->alfi_new_name_len)) returnfalse; if (attrp->alfi_value_len != sizeof(struct xfs_parent_rec)) returnfalse; if (!(attrp->alfi_attr_filter & XFS_ATTR_PARENT)) returnfalse; break; default: returnfalse;
}
/* * We're reconstructing the deferred work state structure from the * recovered log item. Grab a reference to the name/value buffer and * attach it to the new work state.
*/
attr->xattri_nameval = xfs_attri_log_nameval_get(nv);
ASSERT(attr->xattri_nameval);
switch (xfs_attr_intent_op(attr)) { case XFS_ATTRI_OP_FLAGS_PPTR_SET: case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE: case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE:
args->total = xfs_attr_calc_size(args, &local); if (xfs_inode_hasattr(args->dp))
attr->xattri_dela_state = xfs_attr_init_replace_state(args); else
attr->xattri_dela_state = xfs_attr_init_add_state(args); break; case XFS_ATTRI_OP_FLAGS_PPTR_REMOVE: case XFS_ATTRI_OP_FLAGS_REMOVE:
attr->xattri_dela_state = xfs_attr_init_remove_state(args); break;
}
/* * Process an attr intent item that was recovered from the log. We need to * delete the attr that it describes.
*/ STATICint
xfs_attr_recover_work( struct xfs_defer_pending *dfp, struct list_head *capture_list)
{ struct xfs_log_item *lip = dfp->dfp_intent; struct xfs_attri_log_item *attrip = ATTRI_ITEM(lip); struct xfs_attr_intent *attr; struct xfs_mount *mp = lip->li_log->l_mp; struct xfs_inode *ip; struct xfs_da_args *args; struct xfs_trans *tp; struct xfs_trans_res resv; struct xfs_attri_log_format *attrp; struct xfs_attri_log_nameval *nv = attrip->attri_nameval; int error; unsignedint total = 0;
/* * First check the validity of the attr described by the ATTRI. If any * are bad, then assume that all are bad and just toss the ATTRI.
*/
attrp = &attrip->attri_format; if (!xfs_attri_validate(mp, attrp) ||
!xfs_attr_namecheck(attrp->alfi_attr_filter, nv->name.iov_base,
nv->name.iov_len)) return -EFSCORRUPTED;
/* * Create a new log item that shares the same name/value buffer as the * old log item.
*/
new_attrip = xfs_attri_init(tp->t_mountp, old_attrip->attri_nameval);
new_attrp = &new_attrip->attri_format;
/* Get an ATTRD so we can process all the attrs. */ staticstruct xfs_log_item *
xfs_attr_create_done( struct xfs_trans *tp, struct xfs_log_item *intent, unsignedint count)
{ struct xfs_attri_log_item *attrip; struct xfs_attrd_log_item *attrdp;
/* Check the number of log iovecs makes sense for the op code. */
op = xfs_attr_log_item_op(attri_formatp); switch (op) { case XFS_ATTRI_OP_FLAGS_PPTR_REMOVE: case XFS_ATTRI_OP_FLAGS_PPTR_SET: /* Log item, attr name, attr value */ if (item->ri_total != 3) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
name_len = attri_formatp->alfi_name_len;
value_len = attri_formatp->alfi_value_len; break; case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE: /* Log item, attr name, attr value */ if (item->ri_total != 3) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
name_len = attri_formatp->alfi_name_len;
value_len = attri_formatp->alfi_value_len; break; case XFS_ATTRI_OP_FLAGS_REMOVE: /* Log item, attr name */ if (item->ri_total != 2) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
name_len = attri_formatp->alfi_name_len; break; case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE: /* * Log item, attr name, new attr name, attr value, new attr * value
*/ if (item->ri_total != 5) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
name_len = attri_formatp->alfi_old_name_len;
new_name_len = attri_formatp->alfi_new_name_len;
new_value_len = value_len = attri_formatp->alfi_value_len; break; default:
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
i++;
/* Validate the attr name */
attr_name = xfs_attri_validate_name_iovec(mp, attri_formatp,
&item->ri_buf[i], name_len); if (!attr_name) return -EFSCORRUPTED;
i++;
/* Validate the new attr name */ if (new_name_len > 0) {
attr_new_name = xfs_attri_validate_name_iovec(mp,
attri_formatp, &item->ri_buf[i],
new_name_len); if (!attr_new_name) return -EFSCORRUPTED;
i++;
}
/* Validate the attr value, if present */ if (value_len != 0) {
attr_value = xfs_attri_validate_value_iovec(mp, attri_formatp,
&item->ri_buf[i], value_len); if (!attr_value) return -EFSCORRUPTED;
i++;
}
/* Validate the new attr value, if present */ if (new_value_len != 0) {
attr_new_value = xfs_attri_validate_value_iovec(mp,
attri_formatp, &item->ri_buf[i],
new_value_len); if (!attr_new_value) return -EFSCORRUPTED;
i++;
}
/* * Make sure we got the correct number of buffers for the operation * that we just loaded.
*/ if (i != item->ri_total) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
switch (op) { case XFS_ATTRI_OP_FLAGS_REMOVE: /* Regular remove operations operate only on names. */ if (attr_value != NULL || value_len != 0) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
}
fallthrough; case XFS_ATTRI_OP_FLAGS_PPTR_REMOVE: case XFS_ATTRI_OP_FLAGS_PPTR_SET: case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE: /* * Regular xattr set/remove/replace operations require a name * and do not take a newname. Values are optional for set and * replace. * * Name-value set/remove operations must have a name, do not * take a newname, and can take a value.
*/ if (attr_name == NULL || name_len == 0) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
} break; case XFS_ATTRI_OP_FLAGS_PPTR_REPLACE: /* * Name-value replace operations require the caller to * specify the old and new names and values explicitly. * Values are optional.
*/ if (attr_name == NULL || name_len == 0) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
} if (attr_new_name == NULL || new_name_len == 0) {
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
attri_formatp, len); return -EFSCORRUPTED;
} break;
}
/* * Memory alloc failure will cause replay to abort. We attach the * name/value buffer to the recovered incore log item and drop our * reference.
*/
nv = xfs_attri_log_nameval_alloc(attr_name, name_len,
attr_new_name, new_name_len,
attr_value, value_len,
attr_new_value, new_value_len);
/* * This routine is called when an ATTRD format structure is found in a committed * transaction in the log. Its purpose is to cancel the corresponding ATTRI if * it was still in the log. To do this it searches the AIL for the ATTRI with * an id equal to that in the ATTRD format structure. If we find it we drop * the ATTRD reference, which removes the ATTRI from the AIL and frees it.
*/ STATICint
xlog_recover_attrd_commit_pass2( struct xlog *log, struct list_head *buffer_list, struct xlog_recover_item *item,
xfs_lsn_t lsn)
{ struct xfs_attrd_log_format *attrd_formatp;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.