Skip to content

Commit 27eb3af

Browse files
Ming Leiaxboe
authored andcommitted
block: don't hold part0's refcount in IO path
gendisk can't be gone when there is IO activity, so not hold part0's refcount in IO path. Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Yufen Yu <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Hou Tao <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 520138c commit 27eb3af

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

block/blk.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,18 @@ int bdev_resize_partition(struct block_device *bdev, int partno,
378378
int disk_expand_part_tbl(struct gendisk *disk, int target);
379379
int hd_ref_init(struct hd_struct *part);
380380

381-
static inline void hd_struct_get(struct hd_struct *part)
382-
{
383-
percpu_ref_get(&part->ref);
384-
}
385-
381+
/* no need to get/put refcount of part0 */
386382
static inline int hd_struct_try_get(struct hd_struct *part)
387383
{
388-
return percpu_ref_tryget_live(&part->ref);
384+
if (part->partno)
385+
return percpu_ref_tryget_live(&part->ref);
386+
return 1;
389387
}
390388

391389
static inline void hd_struct_put(struct hd_struct *part)
392390
{
393-
percpu_ref_put(&part->ref);
391+
if (part->partno)
392+
percpu_ref_put(&part->ref);
394393
}
395394

396395
static inline void hd_free_part(struct hd_struct *part)

block/genhd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static inline int sector_in_part(struct hd_struct *part, sector_t sector)
345345
*
346346
* CONTEXT:
347347
* RCU read locked. The returned partition pointer is always valid
348-
* because its refcount is grabbed.
348+
* because its refcount is grabbed except for part0, which lifetime
349+
* is same with the disk.
349350
*
350351
* RETURNS:
351352
* Found partition on success, part0 is returned if no partition matches
@@ -378,7 +379,6 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
378379
return part;
379380
}
380381
}
381-
hd_struct_get(&disk->part0);
382382
return &disk->part0;
383383
}
384384

0 commit comments

Comments
 (0)