Skip to content

Commit

Permalink
afs: Wrap most op->error accesses with inline funcs
Browse files Browse the repository at this point in the history
Wrap most op->error accesses with inline funcs which will make it easier
for a subsequent patch to replace op->error with something else.  Two
functions are added to this end:

 (1) afs_op_error() - Get the error code.

 (2) afs_op_set_error() - Set the error code.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
  • Loading branch information
David Howells committed Dec 24, 2023
1 parent 075171f commit 2de5599
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 67 deletions.
38 changes: 19 additions & 19 deletions fs/afs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,14 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry,
* lookups contained therein are stored in the reply without aborting
* the whole operation.
*/
op->error = -ENOTSUPP;
afs_op_set_error(op, -ENOTSUPP);
if (!cookie->one_only) {
op->ops = &afs_inline_bulk_status_operation;
afs_begin_vnode_operation(op);
afs_wait_for_operation(op);
}

if (op->error == -ENOTSUPP) {
if (afs_op_error(op) == -ENOTSUPP) {
/* We could try FS.BulkStatus next, but this aborts the entire
* op if any of the lookups fails - so, for the moment, revert
* to FS.FetchStatus for op->file[1].
Expand All @@ -895,10 +895,10 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry,
afs_begin_vnode_operation(op);
afs_wait_for_operation(op);
}
inode = ERR_PTR(op->error);
inode = ERR_PTR(afs_op_error(op));

out_op:
if (op->error == 0) {
if (!afs_op_error(op)) {
inode = &op->file[1].vnode->netfs.inode;
op->file[1].vnode = NULL;
}
Expand Down Expand Up @@ -1273,7 +1273,7 @@ static void afs_vnode_new_inode(struct afs_operation *op)

_enter("");

ASSERTCMP(op->error, ==, 0);
ASSERTCMP(afs_op_error(op), ==, 0);

inode = afs_iget(op, vp);
if (IS_ERR(inode)) {
Expand All @@ -1286,7 +1286,7 @@ static void afs_vnode_new_inode(struct afs_operation *op)

vnode = AFS_FS_I(inode);
set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
if (!op->error)
if (!afs_op_error(op))
afs_cache_permit(vnode, op->key, vnode->cb_break, &vp->scb);
d_instantiate(op->dentry, inode);
}
Expand Down Expand Up @@ -1320,7 +1320,7 @@ static void afs_create_put(struct afs_operation *op)
{
_enter("op=%08x", op->debug_id);

if (op->error)
if (afs_op_error(op))
d_drop(op->dentry);
}

Expand Down Expand Up @@ -1480,7 +1480,7 @@ static void afs_dir_remove_link(struct afs_operation *op)
struct dentry *dentry = op->dentry;
int ret;

if (op->error != 0 ||
if (afs_op_error(op) ||
(op->file[1].scb.have_status && op->file[1].scb.have_error))
return;
if (d_really_is_positive(dentry))
Expand All @@ -1504,10 +1504,10 @@ static void afs_dir_remove_link(struct afs_operation *op)

ret = afs_validate(vnode, op->key);
if (ret != -ESTALE)
op->error = ret;
afs_op_set_error(op, ret);
}

_debug("nlink %d [val %d]", vnode->netfs.inode.i_nlink, op->error);
_debug("nlink %d [val %d]", vnode->netfs.inode.i_nlink, afs_op_error(op));
}

static void afs_unlink_success(struct afs_operation *op)
Expand Down Expand Up @@ -1538,7 +1538,7 @@ static void afs_unlink_edit_dir(struct afs_operation *op)
static void afs_unlink_put(struct afs_operation *op)
{
_enter("op=%08x", op->debug_id);
if (op->unlink.need_rehash && op->error < 0 && op->error != -ENOENT)
if (op->unlink.need_rehash && afs_op_error(op) < 0 && afs_op_error(op) != -ENOENT)
d_rehash(op->dentry);
}

Expand Down Expand Up @@ -1579,7 +1579,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
/* Try to make sure we have a callback promise on the victim. */
ret = afs_validate(vnode, op->key);
if (ret < 0) {
op->error = ret;
afs_op_set_error(op, ret);
goto error;
}

Expand All @@ -1588,7 +1588,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
spin_unlock(&dentry->d_lock);
/* Start asynchronous writeout of the inode */
write_inode_now(d_inode(dentry), 0);
op->error = afs_sillyrename(dvnode, vnode, dentry, op->key);
afs_op_set_error(op, afs_sillyrename(dvnode, vnode, dentry, op->key));
goto error;
}
if (!d_unhashed(dentry)) {
Expand All @@ -1609,7 +1609,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
/* If there was a conflict with a third party, check the status of the
* unlinked vnode.
*/
if (op->error == 0 && (op->flags & AFS_OPERATION_DIR_CONFLICT)) {
if (afs_op_error(op) == 0 && (op->flags & AFS_OPERATION_DIR_CONFLICT)) {
op->file[1].update_ctime = false;
op->fetch_status.which = 1;
op->ops = &afs_fetch_status_operation;
Expand Down Expand Up @@ -1691,7 +1691,7 @@ static void afs_link_success(struct afs_operation *op)
static void afs_link_put(struct afs_operation *op)
{
_enter("op=%08x", op->debug_id);
if (op->error)
if (afs_op_error(op))
d_drop(op->dentry);
}

Expand Down Expand Up @@ -1889,7 +1889,7 @@ static void afs_rename_put(struct afs_operation *op)
if (op->rename.rehash)
d_rehash(op->rename.rehash);
dput(op->rename.tmp);
if (op->error)
if (afs_op_error(op))
d_rehash(op->dentry);
}

Expand Down Expand Up @@ -1934,7 +1934,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
return PTR_ERR(op);

ret = afs_validate(vnode, op->key);
op->error = ret;
afs_op_set_error(op, ret);
if (ret < 0)
goto error;

Expand Down Expand Up @@ -1971,15 +1971,15 @@ static int afs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
op->rename.tmp = d_alloc(new_dentry->d_parent,
&new_dentry->d_name);
if (!op->rename.tmp) {
op->error = -ENOMEM;
afs_op_nomem(op);
goto error;
}

ret = afs_sillyrename(new_dvnode,
AFS_FS_I(d_inode(new_dentry)),
new_dentry, op->key);
if (ret) {
op->error = ret;
afs_op_set_error(op, ret);
goto error;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void afs_fetch_data_notify(struct afs_operation *op)
{
struct afs_read *req = op->fetch.req;
struct netfs_io_subrequest *subreq = req->subreq;
int error = op->error;
int error = afs_op_error(op);

if (error == -ECONNABORTED)
error = afs_abort_to_error(op->ac.abort_code);
Expand Down Expand Up @@ -271,7 +271,7 @@ static void afs_fetch_data_success(struct afs_operation *op)

static void afs_fetch_data_put(struct afs_operation *op)
{
op->fetch.req->error = op->error;
op->fetch.req->error = afs_op_error(op);
afs_put_read(op->fetch.req);
}

Expand Down
21 changes: 12 additions & 9 deletions fs/afs/fs_operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct afs_operation *afs_alloc_operation(struct key *key, struct afs_volume *vo
op->net = volume->cell->net;
op->cb_v_break = volume->cb_v_break;
op->debug_id = atomic_inc_return(&afs_operation_debug_counter);
op->error = -EDESTADDRREQ;
op->nr_iterations = -1;
afs_op_set_error(op, -EDESTADDRREQ);

_leave(" = [op=%08x]", op->debug_id);
return op;
Expand Down Expand Up @@ -71,7 +71,7 @@ static bool afs_get_io_locks(struct afs_operation *op)
swap(vnode, vnode2);

if (mutex_lock_interruptible(&vnode->io_lock) < 0) {
op->error = -ERESTARTSYS;
afs_op_set_error(op, -ERESTARTSYS);
op->flags |= AFS_OPERATION_STOP;
_leave(" = f [I 0]");
return false;
Expand All @@ -80,7 +80,7 @@ static bool afs_get_io_locks(struct afs_operation *op)

if (vnode2) {
if (mutex_lock_interruptible_nested(&vnode2->io_lock, 1) < 0) {
op->error = -ERESTARTSYS;
afs_op_set_error(op, -ERESTARTSYS);
op->flags |= AFS_OPERATION_STOP;
mutex_unlock(&vnode->io_lock);
op->flags &= ~AFS_OPERATION_LOCK_0;
Expand Down Expand Up @@ -159,11 +159,14 @@ static void afs_end_vnode_operation(struct afs_operation *op)
{
_enter("");

if (op->error == -EDESTADDRREQ ||
op->error == -EADDRNOTAVAIL ||
op->error == -ENETUNREACH ||
op->error == -EHOSTUNREACH)
switch (afs_op_error(op)) {
case -EDESTADDRREQ:
case -EADDRNOTAVAIL:
case -ENETUNREACH:
case -EHOSTUNREACH:
afs_dump_edestaddrreq(op);
break;
}

afs_drop_io_locks(op);

Expand Down Expand Up @@ -209,7 +212,7 @@ void afs_wait_for_operation(struct afs_operation *op)

afs_end_vnode_operation(op);

if (op->error == 0 && op->ops->edit_dir) {
if (!afs_op_error(op) && op->ops->edit_dir) {
_debug("edit_dir");
op->ops->edit_dir(op);
}
Expand All @@ -221,7 +224,7 @@ void afs_wait_for_operation(struct afs_operation *op)
*/
int afs_put_operation(struct afs_operation *op)
{
int i, ret = op->error;
int i, ret = afs_op_error(op);

_enter("op=%08x,%d", op->debug_id, ret);

Expand Down
2 changes: 1 addition & 1 deletion fs/afs/fsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ void afs_fs_inline_bulk_status(struct afs_operation *op)
int i;

if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
op->error = -ENOTSUPP;
afs_op_set_error(op, -ENOTSUPP);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion fs/afs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static void afs_fetch_status_success(struct afs_operation *op)

if (vnode->netfs.inode.i_state & I_NEW) {
ret = afs_inode_init_from_status(op, vp, vnode);
op->error = ret;
afs_op_set_error(op, ret);
if (ret == 0)
afs_cache_permit(vnode, op->key, vp->cb_break_before, &vp->scb);
} else {
Expand Down
20 changes: 15 additions & 5 deletions fs/afs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,6 @@ extern bool afs_begin_vnode_operation(struct afs_operation *);
extern void afs_wait_for_operation(struct afs_operation *);
extern int afs_do_sync_operation(struct afs_operation *);

static inline void afs_op_nomem(struct afs_operation *op)
{
op->error = -ENOMEM;
}

static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
struct afs_vnode *vnode)
{
Expand Down Expand Up @@ -1238,6 +1233,21 @@ static inline void __afs_stat(atomic_t *s)
extern int afs_abort_to_error(u32);
extern void afs_prioritise_error(struct afs_error *, int, u32);

static inline void afs_op_nomem(struct afs_operation *op)
{
op->error = -ENOMEM;
}

static inline int afs_op_error(const struct afs_operation *op)
{
return op->error;
}

static inline int afs_op_set_error(struct afs_operation *op, int error)
{
return op->error = error;
}

/*
* mntpt.c
*/
Expand Down
Loading

0 comments on commit 2de5599

Please sign in to comment.