Skip to content

Commit 39bf094

Browse files
author
David S. Miller
committed
[AFS]: Eliminate cmpxchg() usage in vlocation code.
cmpxchg() is not available on every processor so can't be used in generic code. Replace with spinlock protection on the ->state changes, wakeups, and wait loops. Add what appears to be a missing wakeup on transition to AFS_VL_VALID state in afs_vlocation_updater(). Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 68c708f commit 39bf094

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎fs/afs/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ struct afs_vlocation {
219219
struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
220220
wait_queue_head_t waitq; /* status change waitqueue */
221221
time_t update_at; /* time at which record should be updated */
222-
rwlock_t lock; /* access lock */
222+
spinlock_t lock; /* access lock */
223223
afs_vlocation_state_t state; /* volume location state */
224224
unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
225225
unsigned short upd_busy_cnt; /* EBUSY count during update */

‎fs/afs/vlocation.c‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static struct afs_vlocation *afs_vlocation_alloc(struct afs_cell *cell,
178178
INIT_LIST_HEAD(&vl->grave);
179179
INIT_LIST_HEAD(&vl->update);
180180
init_waitqueue_head(&vl->waitq);
181-
rwlock_init(&vl->lock);
181+
spin_lock_init(&vl->lock);
182182
memcpy(vl->vldb.name, name, namesz);
183183
}
184184

@@ -414,8 +414,10 @@ struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *cell,
414414
ret = afs_vlocation_fill_in_record(vl, key);
415415
if (ret < 0)
416416
goto error_abandon;
417+
spin_lock(&vl->lock);
417418
vl->state = AFS_VL_VALID;
418419
wake_up(&vl->waitq);
420+
spin_unlock(&vl->lock);
419421

420422
/* schedule for regular updates */
421423
afs_vlocation_queue_for_updates(vl);
@@ -434,38 +436,43 @@ struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *cell,
434436
up_write(&cell->vl_sem);
435437

436438
/* see if it was an abandoned record that we might try filling in */
439+
spin_lock(&vl->lock);
437440
while (vl->state != AFS_VL_VALID) {
438441
afs_vlocation_state_t state = vl->state;
439442

440443
_debug("invalid [state %d]", state);
441444

442445
if ((state == AFS_VL_NEW || state == AFS_VL_NO_VOLUME)) {
443-
if (cmpxchg(&vl->state, state, AFS_VL_CREATING) ==
444-
state)
445-
goto fill_in_record;
446-
continue;
446+
vl->state = AFS_VL_CREATING;
447+
spin_unlock(&vl->lock);
448+
goto fill_in_record;
447449
}
448450

449451
/* must now wait for creation or update by someone else to
450452
* complete */
451453
_debug("wait");
452454

455+
spin_unlock(&vl->lock);
453456
ret = wait_event_interruptible(
454457
vl->waitq,
455458
vl->state == AFS_VL_NEW ||
456459
vl->state == AFS_VL_VALID ||
457460
vl->state == AFS_VL_NO_VOLUME);
458461
if (ret < 0)
459462
goto error;
463+
spin_lock(&vl->lock);
460464
}
465+
spin_unlock(&vl->lock);
461466

462467
success:
463468
_leave(" = %p",vl);
464469
return vl;
465470

466471
error_abandon:
472+
spin_lock(&vl->lock);
467473
vl->state = AFS_VL_NEW;
468474
wake_up(&vl->waitq);
475+
spin_unlock(&vl->lock);
469476
error:
470477
ASSERT(vl != NULL);
471478
afs_put_vlocation(vl);
@@ -663,10 +670,12 @@ static void afs_vlocation_updater(struct work_struct *work)
663670
vl->upd_busy_cnt = 0;
664671

665672
ret = afs_vlocation_update_record(vl, NULL, &vldb);
673+
spin_lock(&vl->lock);
666674
switch (ret) {
667675
case 0:
668676
afs_vlocation_apply_update(vl, &vldb);
669677
vl->state = AFS_VL_VALID;
678+
wake_up(&vl->waitq);
670679
break;
671680
case -ENOMEDIUM:
672681
vl->state = AFS_VL_VOLUME_DELETED;
@@ -675,6 +684,7 @@ static void afs_vlocation_updater(struct work_struct *work)
675684
vl->state = AFS_VL_UNCERTAIN;
676685
break;
677686
}
687+
spin_unlock(&vl->lock);
678688

679689
/* and then reschedule */
680690
_debug("reschedule");

0 commit comments

Comments
 (0)