View | Details | Raw Unified | Return to bug 104046
Collapse All | Expand All

(-)diff/fs/block_dev.c (-28 / +4 lines)
Lines 445-478 Link Here
445
445
446
int bd_claim(struct block_device *bdev, void *holder)
446
int bd_claim(struct block_device *bdev, void *holder)
447
{
447
{
448
	int res;
448
	int res = -EBUSY;
449
	spin_lock(&bdev_lock);
449
	spin_lock(&bdev_lock);
450
450
	if (!bdev->bd_holder || bdev->bd_holder == holder) {
451
	/* first decide result */
452
	if (bdev->bd_holder == holder)
453
		res = 0;	 /* already a holder */
454
	else if (bdev->bd_holder != NULL)
455
		res = -EBUSY; 	 /* held by someone else */
456
	else if (bdev->bd_contains == bdev)
457
		res = 0;  	 /* is a whole device which isn't held */
458
459
	else if (bdev->bd_contains->bd_holder == bd_claim)
460
		res = 0; 	 /* is a partition of a device that is being partitioned */
461
	else if (bdev->bd_contains->bd_holder != NULL)
462
		res = -EBUSY;	 /* is a partition of a held device */
463
	else
464
		res = 0;	 /* is a partition of an un-held device */
465
466
	/* now impose change */
467
	if (res==0) {
468
		/* note that for a whole device bd_holders
469
		 * will be incremented twice, and bd_holder will
470
		 * be set to bd_claim before being set to holder
471
		 */
472
		bdev->bd_contains->bd_holders ++;
473
		bdev->bd_contains->bd_holder = bd_claim;
474
		bdev->bd_holders++;
475
		bdev->bd_holder = holder;
451
		bdev->bd_holder = holder;
452
		bdev->bd_holders++;
453
		res = 0;
476
	}
454
	}
477
	spin_unlock(&bdev_lock);
455
	spin_unlock(&bdev_lock);
478
	return res;
456
	return res;
Lines 483-490 Link Here
483
void bd_release(struct block_device *bdev)
461
void bd_release(struct block_device *bdev)
484
{
462
{
485
	spin_lock(&bdev_lock);
463
	spin_lock(&bdev_lock);
486
	if (!--bdev->bd_contains->bd_holders)
487
		bdev->bd_contains->bd_holder = NULL;
488
	if (!--bdev->bd_holders)
464
	if (!--bdev->bd_holders)
489
		bdev->bd_holder = NULL;
465
		bdev->bd_holder = NULL;
490
	spin_unlock(&bdev_lock);
466
	spin_unlock(&bdev_lock);

Return to bug 104046