Skip to content

Commit 7ffbf33

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: target: iblock: Allow iblock devices to be shared
We might be running a local application that also interacts with the backing device. In this setup we have some clustering type of software that manages the ownwer of it, so we don't want the kernel to restrict us. This patch allows the user to control if the driver gets exclusive access. Signed-off-by: Mike Christie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 35dabf4 commit 7ffbf33

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

drivers/target/target_core_iblock.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static struct se_device *iblock_alloc_device(struct se_hba *hba, const char *nam
6464
pr_err("Unable to allocate struct iblock_dev\n");
6565
return NULL;
6666
}
67+
ib_dev->ibd_exclusive = true;
6768

6869
ib_dev->ibd_plug = kcalloc(nr_cpu_ids, sizeof(*ib_dev->ibd_plug),
6970
GFP_KERNEL);
@@ -95,6 +96,7 @@ static int iblock_configure_device(struct se_device *dev)
9596
struct block_device *bd;
9697
struct blk_integrity *bi;
9798
blk_mode_t mode = BLK_OPEN_READ;
99+
void *holder = ib_dev;
98100
unsigned int max_write_zeroes_sectors;
99101
int ret;
100102

@@ -109,15 +111,18 @@ static int iblock_configure_device(struct se_device *dev)
109111
goto out;
110112
}
111113

112-
pr_debug( "IBLOCK: Claiming struct block_device: %s\n",
113-
ib_dev->ibd_udev_path);
114+
pr_debug("IBLOCK: Claiming struct block_device: %s: %d\n",
115+
ib_dev->ibd_udev_path, ib_dev->ibd_exclusive);
114116

115117
if (!ib_dev->ibd_readonly)
116118
mode |= BLK_OPEN_WRITE;
117119
else
118120
dev->dev_flags |= DF_READ_ONLY;
119121

120-
bdev_file = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
122+
if (!ib_dev->ibd_exclusive)
123+
holder = NULL;
124+
125+
bdev_file = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, holder,
121126
NULL);
122127
if (IS_ERR(bdev_file)) {
123128
ret = PTR_ERR(bdev_file);
@@ -560,13 +565,14 @@ iblock_execute_write_same(struct se_cmd *cmd)
560565
}
561566

562567
enum {
563-
Opt_udev_path, Opt_readonly, Opt_force, Opt_err
568+
Opt_udev_path, Opt_readonly, Opt_force, Opt_exclusive, Opt_err,
564569
};
565570

566571
static match_table_t tokens = {
567572
{Opt_udev_path, "udev_path=%s"},
568573
{Opt_readonly, "readonly=%d"},
569574
{Opt_force, "force=%d"},
575+
{Opt_exclusive, "exclusive=%d"},
570576
{Opt_err, NULL}
571577
};
572578

@@ -576,7 +582,7 @@ static ssize_t iblock_set_configfs_dev_params(struct se_device *dev,
576582
struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
577583
char *orig, *ptr, *arg_p, *opts;
578584
substring_t args[MAX_OPT_ARGS];
579-
int ret = 0, token;
585+
int ret = 0, token, tmp_exclusive;
580586
unsigned long tmp_readonly;
581587

582588
opts = kstrdup(page, GFP_KERNEL);
@@ -623,6 +629,22 @@ static ssize_t iblock_set_configfs_dev_params(struct se_device *dev,
623629
ib_dev->ibd_readonly = tmp_readonly;
624630
pr_debug("IBLOCK: readonly: %d\n", ib_dev->ibd_readonly);
625631
break;
632+
case Opt_exclusive:
633+
arg_p = match_strdup(&args[0]);
634+
if (!arg_p) {
635+
ret = -ENOMEM;
636+
break;
637+
}
638+
ret = kstrtoint(arg_p, 0, &tmp_exclusive);
639+
kfree(arg_p);
640+
if (ret < 0) {
641+
pr_err("kstrtoul() failed for exclusive=\n");
642+
goto out;
643+
}
644+
ib_dev->ibd_exclusive = tmp_exclusive;
645+
pr_debug("IBLOCK: exclusive: %d\n",
646+
ib_dev->ibd_exclusive);
647+
break;
626648
case Opt_force:
627649
break;
628650
default:
@@ -647,6 +669,7 @@ static ssize_t iblock_show_configfs_dev_params(struct se_device *dev, char *b)
647669
bl += sprintf(b + bl, " UDEV PATH: %s",
648670
ib_dev->ibd_udev_path);
649671
bl += sprintf(b + bl, " readonly: %d\n", ib_dev->ibd_readonly);
672+
bl += sprintf(b + bl, " exclusive: %d\n", ib_dev->ibd_exclusive);
650673

651674
bl += sprintf(b + bl, " ");
652675
if (bd) {

drivers/target/target_core_iblock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct iblock_dev {
3434
struct block_device *ibd_bd;
3535
struct file *ibd_bdev_file;
3636
bool ibd_readonly;
37+
bool ibd_exclusive;
3738
struct iblock_dev_plug *ibd_plug;
3839
} ____cacheline_aligned;
3940

0 commit comments

Comments
 (0)