Skip to content

Commit

Permalink
Merge tag 'for-6.4/block-2023-05-06' of git://git.kernel.dk/linux
Browse files Browse the repository at this point in the history
Pull more block updates from Jens Axboe:

 - MD pull request via Song:
      - Improve raid5 sequential IO performance on spinning disks, which
        fixes a regression since v6.0 (Jan Kara)
      - Fix bitmap offset types, which fixes an issue introduced in this
        merge window (Jonathan Derrick)

 - Cleanup of hweight type used for cgroup writeback (Maxim)

 - Fix a regression with the "has_submit_bio" changes across partitions
   (Ming)

 - Cleanup of QUEUE_FLAG_ADD_RANDOM clearing.

   We used to set this flag on queues non blk-mq queues, and hence some
   drivers clear it unconditionally. Since all of these have since been
   converted to true blk-mq drivers, drop the useless clear as the bit
   is not set (Chaitanya)

 - Fix the flags being set in a bio for a flush for drbd (Christoph)

 - Cleanup and deduplication of the code handling setting block device
   capacity (Damien)

 - Fix for ublk handling IO timeouts (Ming)

 - Fix for a regression in blk-cgroup teardown (Tao)

 - NBD documentation and code fixes (Eric)

 - Convert blk-integrity to using device_attributes rather than a second
   kobject to manage lifetimes (Thomas)

* tag 'for-6.4/block-2023-05-06' of git://git.kernel.dk/linux:
  ublk: add timeout handler
  drbd: correctly submit flush bio on barrier
  mailmap: add mailmap entries for Jens Axboe
  block: Skip destroyed blkg when restart in blkg_destroy_all()
  writeback: fix call of incorrect macro
  md: Fix bitmap offset type in sb writer
  md/raid5: Improve performance for sequential IO
  docs nbd: userspace NBD now favors github over sourceforge
  block nbd: use req.cookie instead of req.handle
  uapi nbd: add cookie alias to handle
  uapi nbd: improve doc links to userspace spec
  blk-integrity: register sysfs attributes on struct device
  blk-integrity: convert to struct device_attribute
  blk-integrity: use sysfs_emit
  block/drivers: remove dead clear of random flag
  block: sync part's ->bd_has_submit_bio with disk's
  block: Cleanup set_capacity()/bdev_set_nr_sectors()
  • Loading branch information
torvalds committed May 6, 2023
2 parents 7644c82 + c0b79b0 commit a3b111b
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 170 deletions.
5 changes: 4 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ Jeff Garzik <[email protected]>
Jeff Layton <[email protected]> <[email protected]>
Jeff Layton <[email protected]> <[email protected]>
Jeff Layton <[email protected]> <[email protected]>
Jens Axboe <[email protected]>
Jens Axboe <[email protected]> <[email protected]>
Jens Axboe <[email protected]> <[email protected]>
Jens Axboe <[email protected]> <[email protected]>
Jens Axboe <[email protected]> <[email protected]>
Jens Osterkamp <[email protected]>
Jernej Skrabec <[email protected]> <[email protected]>
Jessica Zhang <[email protected]> <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/admin-guide/blockdev/nbd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ to borrow disk space from another computer.
Unlike NFS, it is possible to put any filesystem on it, etc.

For more information, or to download the nbd-client and nbd-server
tools, go to http://nbd.sf.net/.
tools, go to https://github.com/NetworkBlockDevice/nbd.

The nbd kernel module need only be installed on the client
system, as the nbd-server is completely in userspace. In fact,
Expand Down
13 changes: 12 additions & 1 deletion block/bdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,11 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
bdev->bd_partno = partno;
bdev->bd_inode = inode;
bdev->bd_queue = disk->queue;
if (partno)
bdev->bd_has_submit_bio = disk->part0->bd_has_submit_bio;
else
bdev->bd_has_submit_bio = false;
bdev->bd_stats = alloc_percpu(struct disk_stats);
bdev->bd_has_submit_bio = false;
if (!bdev->bd_stats) {
iput(inode);
return NULL;
Expand All @@ -428,6 +431,14 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
return bdev;
}

void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
{
spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock);
}

void bdev_add(struct block_device *bdev, dev_t dev)
{
bdev->bd_dev = dev;
Expand Down
3 changes: 3 additions & 0 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ static void blkg_destroy_all(struct gendisk *disk)
list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
struct blkcg *blkcg = blkg->blkcg;

if (hlist_unhashed(&blkg->blkcg_node))
continue;

spin_lock(&blkcg->lock);
blkg_destroy(blkg);
spin_unlock(&blkcg->lock);
Expand Down
175 changes: 61 additions & 114 deletions block/blk-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,61 +212,44 @@ bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
return true;
}

struct integrity_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct blk_integrity *, char *);
ssize_t (*store)(struct blk_integrity *, const char *, size_t);
};

static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr,
char *page)
static inline struct blk_integrity *dev_to_bi(struct device *dev)
{
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = &disk->queue->integrity;
struct integrity_sysfs_entry *entry =
container_of(attr, struct integrity_sysfs_entry, attr);

return entry->show(bi, page);
return &dev_to_disk(dev)->queue->integrity;
}

static ssize_t integrity_attr_store(struct kobject *kobj,
struct attribute *attr, const char *page,
size_t count)
static ssize_t format_show(struct device *dev, struct device_attribute *attr,
char *page)
{
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = &disk->queue->integrity;
struct integrity_sysfs_entry *entry =
container_of(attr, struct integrity_sysfs_entry, attr);
ssize_t ret = 0;
struct blk_integrity *bi = dev_to_bi(dev);

if (entry->store)
ret = entry->store(bi, page, count);

return ret;
}

static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
{
if (bi->profile && bi->profile->name)
return sprintf(page, "%s\n", bi->profile->name);
else
return sprintf(page, "none\n");
return sysfs_emit(page, "%s\n", bi->profile->name);
return sysfs_emit(page, "none\n");
}

static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page)
static ssize_t tag_size_show(struct device *dev, struct device_attribute *attr,
char *page)
{
return sprintf(page, "%u\n", bi->tag_size);
struct blk_integrity *bi = dev_to_bi(dev);

return sysfs_emit(page, "%u\n", bi->tag_size);
}

static ssize_t integrity_interval_show(struct blk_integrity *bi, char *page)
static ssize_t protection_interval_bytes_show(struct device *dev,
struct device_attribute *attr,
char *page)
{
return sprintf(page, "%u\n",
bi->interval_exp ? 1 << bi->interval_exp : 0);
struct blk_integrity *bi = dev_to_bi(dev);

return sysfs_emit(page, "%u\n",
bi->interval_exp ? 1 << bi->interval_exp : 0);
}

static ssize_t integrity_verify_store(struct blk_integrity *bi,
const char *page, size_t count)
static ssize_t read_verify_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count)
{
struct blk_integrity *bi = dev_to_bi(dev);
char *p = (char *) page;
unsigned long val = simple_strtoul(p, &p, 10);

Expand All @@ -278,14 +261,20 @@ static ssize_t integrity_verify_store(struct blk_integrity *bi,
return count;
}

static ssize_t integrity_verify_show(struct blk_integrity *bi, char *page)
static ssize_t read_verify_show(struct device *dev,
struct device_attribute *attr, char *page)
{
return sprintf(page, "%d\n", (bi->flags & BLK_INTEGRITY_VERIFY) != 0);
struct blk_integrity *bi = dev_to_bi(dev);

return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_VERIFY));
}

static ssize_t integrity_generate_store(struct blk_integrity *bi,
const char *page, size_t count)
static ssize_t write_generate_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count)
{
struct blk_integrity *bi = dev_to_bi(dev);

char *p = (char *) page;
unsigned long val = simple_strtoul(p, &p, 10);

Expand All @@ -297,68 +286,44 @@ static ssize_t integrity_generate_store(struct blk_integrity *bi,
return count;
}

static ssize_t integrity_generate_show(struct blk_integrity *bi, char *page)
static ssize_t write_generate_show(struct device *dev,
struct device_attribute *attr, char *page)
{
return sprintf(page, "%d\n", (bi->flags & BLK_INTEGRITY_GENERATE) != 0);
}
struct blk_integrity *bi = dev_to_bi(dev);

static ssize_t integrity_device_show(struct blk_integrity *bi, char *page)
{
return sprintf(page, "%u\n",
(bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE) != 0);
return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_GENERATE));
}

static struct integrity_sysfs_entry integrity_format_entry = {
.attr = { .name = "format", .mode = 0444 },
.show = integrity_format_show,
};

static struct integrity_sysfs_entry integrity_tag_size_entry = {
.attr = { .name = "tag_size", .mode = 0444 },
.show = integrity_tag_size_show,
};

static struct integrity_sysfs_entry integrity_interval_entry = {
.attr = { .name = "protection_interval_bytes", .mode = 0444 },
.show = integrity_interval_show,
};

static struct integrity_sysfs_entry integrity_verify_entry = {
.attr = { .name = "read_verify", .mode = 0644 },
.show = integrity_verify_show,
.store = integrity_verify_store,
};
static ssize_t device_is_integrity_capable_show(struct device *dev,
struct device_attribute *attr,
char *page)
{
struct blk_integrity *bi = dev_to_bi(dev);

static struct integrity_sysfs_entry integrity_generate_entry = {
.attr = { .name = "write_generate", .mode = 0644 },
.show = integrity_generate_show,
.store = integrity_generate_store,
};
return sysfs_emit(page, "%u\n",
!!(bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE));
}

static struct integrity_sysfs_entry integrity_device_entry = {
.attr = { .name = "device_is_integrity_capable", .mode = 0444 },
.show = integrity_device_show,
};
static DEVICE_ATTR_RO(format);
static DEVICE_ATTR_RO(tag_size);
static DEVICE_ATTR_RO(protection_interval_bytes);
static DEVICE_ATTR_RW(read_verify);
static DEVICE_ATTR_RW(write_generate);
static DEVICE_ATTR_RO(device_is_integrity_capable);

static struct attribute *integrity_attrs[] = {
&integrity_format_entry.attr,
&integrity_tag_size_entry.attr,
&integrity_interval_entry.attr,
&integrity_verify_entry.attr,
&integrity_generate_entry.attr,
&integrity_device_entry.attr,
NULL,
&dev_attr_format.attr,
&dev_attr_tag_size.attr,
&dev_attr_protection_interval_bytes.attr,
&dev_attr_read_verify.attr,
&dev_attr_write_generate.attr,
&dev_attr_device_is_integrity_capable.attr,
NULL
};
ATTRIBUTE_GROUPS(integrity);

static const struct sysfs_ops integrity_ops = {
.show = &integrity_attr_show,
.store = &integrity_attr_store,
};

static const struct kobj_type integrity_ktype = {
.default_groups = integrity_groups,
.sysfs_ops = &integrity_ops,
const struct attribute_group blk_integrity_attr_group = {
.name = "integrity",
.attrs = integrity_attrs,
};

static blk_status_t blk_integrity_nop_fn(struct blk_integrity_iter *iter)
Expand Down Expand Up @@ -437,21 +402,3 @@ void blk_integrity_unregister(struct gendisk *disk)
memset(bi, 0, sizeof(*bi));
}
EXPORT_SYMBOL(blk_integrity_unregister);

int blk_integrity_add(struct gendisk *disk)
{
int ret;

ret = kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype,
&disk_to_dev(disk)->kobj, "%s", "integrity");
if (!ret)
kobject_uevent(&disk->integrity_kobj, KOBJ_ADD);
return ret;
}

void blk_integrity_del(struct gendisk *disk)
{
kobject_uevent(&disk->integrity_kobj, KOBJ_REMOVE);
kobject_del(&disk->integrity_kobj);
kobject_put(&disk->integrity_kobj);
}
12 changes: 3 additions & 9 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ static inline bool integrity_req_gap_front_merge(struct request *req,
bip_next->bip_vec[0].bv_offset);
}

int blk_integrity_add(struct gendisk *disk);
void blk_integrity_del(struct gendisk *);
extern const struct attribute_group blk_integrity_attr_group;
#else /* CONFIG_BLK_DEV_INTEGRITY */
static inline bool blk_integrity_merge_rq(struct request_queue *rq,
struct request *r1, struct request *r2)
Expand Down Expand Up @@ -248,13 +247,6 @@ static inline bool bio_integrity_endio(struct bio *bio)
static inline void bio_integrity_free(struct bio *bio)
{
}
static inline int blk_integrity_add(struct gendisk *disk)
{
return 0;
}
static inline void blk_integrity_del(struct gendisk *disk)
{
}
#endif /* CONFIG_BLK_DEV_INTEGRITY */

unsigned long blk_rq_timeout(unsigned long timeout);
Expand Down Expand Up @@ -419,6 +411,8 @@ int bdev_resize_partition(struct gendisk *disk, int partno, sector_t start,
sector_t length);
void blk_drop_partitions(struct gendisk *disk);

void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors);

struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
struct lock_class_key *lkclass);

Expand Down
19 changes: 5 additions & 14 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ static DEFINE_IDA(ext_devt_ida);

void set_capacity(struct gendisk *disk, sector_t sectors)
{
struct block_device *bdev = disk->part0;

spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock);
bdev_set_nr_sectors(disk->part0, sectors);
}
EXPORT_SYMBOL(set_capacity);

Expand Down Expand Up @@ -487,15 +482,11 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
*/
pm_runtime_set_memalloc_noio(ddev, true);

ret = blk_integrity_add(disk);
if (ret)
goto out_del_block_link;

disk->part0->bd_holder_dir =
kobject_create_and_add("holders", &ddev->kobj);
if (!disk->part0->bd_holder_dir) {
ret = -ENOMEM;
goto out_del_integrity;
goto out_del_block_link;
}
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
if (!disk->slave_dir) {
Expand Down Expand Up @@ -558,8 +549,6 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
disk->slave_dir = NULL;
out_put_holder_dir:
kobject_put(disk->part0->bd_holder_dir);
out_del_integrity:
blk_integrity_del(disk);
out_del_block_link:
sysfs_remove_link(block_depr, dev_name(ddev));
out_device_del:
Expand Down Expand Up @@ -621,7 +610,6 @@ void del_gendisk(struct gendisk *disk)
if (WARN_ON_ONCE(!disk_live(disk) && !(disk->flags & GENHD_FL_HIDDEN)))
return;

blk_integrity_del(disk);
disk_del_events(disk);

mutex_lock(&disk->open_mutex);
Expand Down Expand Up @@ -1155,6 +1143,9 @@ static const struct attribute_group *disk_attr_groups[] = {
&disk_attr_group,
#ifdef CONFIG_BLK_DEV_IO_TRACE
&blk_trace_attr_group,
#endif
#ifdef CONFIG_BLK_DEV_INTEGRITY
&blk_integrity_attr_group,
#endif
NULL
};
Expand Down
8 changes: 0 additions & 8 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ static int (*check_part[])(struct parsed_partitions *) = {
NULL
};

static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
{
spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock);
}

static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
{
struct parsed_partitions *state;
Expand Down
Loading

0 comments on commit a3b111b

Please sign in to comment.