Skip to content

Commit 8d76349

Browse files
committed
FS-Cache: Exclusive op submission can BUG if there's been an I/O error
The function to submit an exclusive op (fscache_submit_exclusive_op()) can BUG if there's been an I/O error because it may see the parent cache object in an unexpected state. It should only BUG if there hasn't been an I/O error. In this case the problem was produced by remounting the cache partition to be R/O. The EROFS state was detected and the cache was aborted, but not everything handled the aborting correctly. SysRq : Emergency Remount R/O EXT4-fs (sda6): re-mounted. Opts: (null) Emergency Remount complete CacheFiles: I/O Error: Failed to update xattr with error -30 FS-Cache: Cache cachefiles stopped due to I/O error ------------[ cut here ]------------ kernel BUG at fs/fscache/operation.c:128! invalid opcode: 0000 [#1] SMP CPU 0 Modules linked in: cachefiles nfs fscache auth_rpcgss nfs_acl lockd sunrpc Pid: 6612, comm: kworker/u:2 Not tainted 3.1.0-rc8-fsdevel+ torvalds#1093 /DG965RY RIP: 0010:[<ffffffffa00739c0>] [<ffffffffa00739c0>] fscache_submit_exclusive_op+0x2ad/0x2c2 [fscache] RSP: 0018:ffff880000853d40 EFLAGS: 00010206 RAX: ffff880038ac72a8 RBX: ffff8800181f2260 RCX: ffffffff81f2b2b0 RDX: 0000000000000001 RSI: ffffffff8179a478 RDI: ffff8800181f2280 RBP: ffff880000853d60 R08: 0000000000000002 R09: 0000000000000000 R10: 0000000000000001 R11: 0000000000000001 R12: ffff880038ac7268 R13: ffff8800181f2280 R14: ffff88003a359190 R15: 000000010122b162 FS: 0000000000000000(0000) GS:ffff88003bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 00000034cc4a77f0 CR3: 0000000010e96000 CR4: 00000000000006f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process kworker/u:2 (pid: 6612, threadinfo ffff880000852000, task ffff880014c3c040) Stack: ffff8800181f2260 ffff8800181f2310 ffff880038ac7268 ffff8800181f2260 ffff880000853dc0 ffffffffa0072375 ffff880037ecfe00 ffff88003a359198 ffff880000853dc0 0000000000000246 0000000000000000 ffff88000a91d308 Call Trace: [<ffffffffa0072375>] fscache_object_work_func+0x792/0xe65 [fscache] [<ffffffff81047e44>] process_one_work+0x1eb/0x37f [<ffffffff81047de6>] ? process_one_work+0x18d/0x37f [<ffffffffa0071be3>] ? fscache_enqueue_dependents+0xd8/0xd8 [fscache] [<ffffffff810482e4>] worker_thread+0x15a/0x21a [<ffffffff8104818a>] ? rescuer_thread+0x188/0x188 [<ffffffff8104bf96>] kthread+0x7f/0x87 [<ffffffff813ad6f4>] kernel_thread_helper+0x4/0x10 [<ffffffff81026b98>] ? finish_task_switch+0x45/0xc0 [<ffffffff813abd1d>] ? retint_restore_args+0xe/0xe [<ffffffff8104bf17>] ? __init_kthread_worker+0x53/0x53 [<ffffffff813ad6f0>] ? gs_change+0xb/0xb Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 75bc411 commit 8d76349

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

fs/fscache/internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ extern const struct file_operations fscache_stats_fops;
288288
static inline void fscache_raise_event(struct fscache_object *object,
289289
unsigned event)
290290
{
291+
BUG_ON(event >= NR_FSCACHE_OBJECT_EVENTS);
291292
if (!test_and_set_bit(event, &object->events) &&
292293
test_bit(event, &object->event_mask))
293294
fscache_enqueue_object(object);

fs/fscache/object.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
103103
{
104104
enum fscache_object_state new_state;
105105
struct fscache_cookie *cookie;
106+
int event;
106107

107108
ASSERT(object != NULL);
108109

@@ -275,7 +276,8 @@ static void fscache_object_state_machine(struct fscache_object *object)
275276

276277
/* determine the transition from a lookup state */
277278
lookup_transit:
278-
switch (fls(object->events & object->event_mask) - 1) {
279+
event = fls(object->events & object->event_mask) - 1;
280+
switch (event) {
279281
case FSCACHE_OBJECT_EV_WITHDRAW:
280282
case FSCACHE_OBJECT_EV_RETIRE:
281283
case FSCACHE_OBJECT_EV_RELEASE:
@@ -292,7 +294,8 @@ static void fscache_object_state_machine(struct fscache_object *object)
292294

293295
/* determine the transition from an active state */
294296
active_transit:
295-
switch (fls(object->events & object->event_mask) - 1) {
297+
event = fls(object->events & object->event_mask) - 1;
298+
switch (event) {
296299
case FSCACHE_OBJECT_EV_WITHDRAW:
297300
case FSCACHE_OBJECT_EV_RETIRE:
298301
case FSCACHE_OBJECT_EV_RELEASE:
@@ -314,7 +317,8 @@ static void fscache_object_state_machine(struct fscache_object *object)
314317

315318
/* determine the transition from a terminal state */
316319
terminal_transit:
317-
switch (fls(object->events & object->event_mask) - 1) {
320+
event = fls(object->events & object->event_mask) - 1;
321+
switch (event) {
318322
case FSCACHE_OBJECT_EV_WITHDRAW:
319323
new_state = FSCACHE_OBJECT_WITHDRAWING;
320324
goto change_state;
@@ -347,8 +351,8 @@ static void fscache_object_state_machine(struct fscache_object *object)
347351

348352
unsupported_event:
349353
printk(KERN_ERR "FS-Cache:"
350-
" Unsupported event %lx [mask %lx] in state %s\n",
351-
object->events, object->event_mask,
354+
" Unsupported event %d [%lx/%lx] in state %s\n",
355+
event, object->events, object->event_mask,
352356
fscache_object_states[object->state]);
353357
BUG();
354358
}
@@ -945,7 +949,7 @@ static void fscache_invalidate_object(struct fscache_object *object)
945949

946950
spin_lock(&cookie->lock);
947951
if (fscache_submit_exclusive_op(object, op) < 0)
948-
BUG();
952+
goto submit_op_failed;
949953
spin_unlock(&cookie->lock);
950954
fscache_put_operation(op);
951955

@@ -960,4 +964,11 @@ static void fscache_invalidate_object(struct fscache_object *object)
960964
*/
961965
fscache_invalidation_complete(cookie);
962966
_leave("");
967+
return;
968+
969+
submit_op_failed:
970+
spin_unlock(&cookie->lock);
971+
kfree(op);
972+
fscache_raise_event(object, FSCACHE_OBJECT_EV_ERROR);
973+
_leave(" [EIO]");
963974
}

fs/fscache/operation.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ static void fscache_run_op(struct fscache_object *object,
8484
int fscache_submit_exclusive_op(struct fscache_object *object,
8585
struct fscache_operation *op)
8686
{
87+
int ret;
88+
8789
_enter("{OBJ%x OP%x},", object->debug_id, op->debug_id);
8890

8991
ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED);
@@ -116,20 +118,25 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
116118

117119
/* need to issue a new write op after this */
118120
clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags);
121+
ret = 0;
119122
} else if (object->state == FSCACHE_OBJECT_CREATING) {
120123
op->object = object;
121124
object->n_ops++;
122125
object->n_exclusive++; /* reads and writes must wait */
123126
atomic_inc(&op->usage);
124127
list_add_tail(&op->pend_link, &object->pending_ops);
125128
fscache_stat(&fscache_n_op_pend);
129+
ret = 0;
126130
} else {
127-
/* not allowed to submit ops in any other state */
128-
BUG();
131+
/* If we're in any other state, there must have been an I/O
132+
* error of some nature.
133+
*/
134+
ASSERT(test_bit(FSCACHE_IOERROR, &object->cache->flags));
135+
ret = -EIO;
129136
}
130137

131138
spin_unlock(&object->lock);
132-
return 0;
139+
return ret;
133140
}
134141

135142
/*

0 commit comments

Comments
 (0)