Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target/iblock: Add parameter to specify read-only devices

see https://bugzilla.redhat.com/show_bug.cgi?id=818855

Adds a parameter so read-only block devices may be registered as
LIO backstores.

Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Andy Grover and committed by
Nicholas Bellinger
44bfd018 7acd5707

+29 -7
+28 -7
drivers/target/target_core_iblock.c
··· 96 96 struct request_queue *q; 97 97 struct queue_limits *limits; 98 98 u32 dev_flags = 0; 99 + fmode_t mode; 99 100 int ret = -EINVAL; 100 101 101 102 if (!ib_dev) { ··· 118 117 pr_debug( "IBLOCK: Claiming struct block_device: %s\n", 119 118 ib_dev->ibd_udev_path); 120 119 121 - bd = blkdev_get_by_path(ib_dev->ibd_udev_path, 122 - FMODE_WRITE|FMODE_READ|FMODE_EXCL, ib_dev); 120 + mode = FMODE_READ|FMODE_EXCL; 121 + if (!ib_dev->ibd_readonly) 122 + mode |= FMODE_WRITE; 123 + 124 + bd = blkdev_get_by_path(ib_dev->ibd_udev_path, mode, ib_dev); 123 125 if (IS_ERR(bd)) { 124 126 ret = PTR_ERR(bd); 125 127 goto failed; ··· 327 323 } 328 324 329 325 enum { 330 - Opt_udev_path, Opt_force, Opt_err 326 + Opt_udev_path, Opt_readonly, Opt_force, Opt_err 331 327 }; 332 328 333 329 static match_table_t tokens = { 334 330 {Opt_udev_path, "udev_path=%s"}, 331 + {Opt_readonly, "readonly=%d"}, 335 332 {Opt_force, "force=%d"}, 336 333 {Opt_err, NULL} 337 334 }; ··· 345 340 char *orig, *ptr, *arg_p, *opts; 346 341 substring_t args[MAX_OPT_ARGS]; 347 342 int ret = 0, token; 343 + unsigned long tmp_readonly; 348 344 349 345 opts = kstrdup(page, GFP_KERNEL); 350 346 if (!opts) ··· 377 371 pr_debug("IBLOCK: Referencing UDEV path: %s\n", 378 372 ib_dev->ibd_udev_path); 379 373 ib_dev->ibd_flags |= IBDF_HAS_UDEV_PATH; 374 + break; 375 + case Opt_readonly: 376 + arg_p = match_strdup(&args[0]); 377 + if (!arg_p) { 378 + ret = -ENOMEM; 379 + break; 380 + } 381 + ret = strict_strtoul(arg_p, 0, &tmp_readonly); 382 + kfree(arg_p); 383 + if (ret < 0) { 384 + pr_err("strict_strtoul() failed for" 385 + " readonly=\n"); 386 + goto out; 387 + } 388 + ib_dev->ibd_readonly = tmp_readonly; 389 + pr_debug("IBLOCK: readonly: %d\n", ib_dev->ibd_readonly); 380 390 break; 381 391 case Opt_force: 382 392 break; ··· 433 411 if (bd) 434 412 bl += sprintf(b + bl, "iBlock device: %s", 435 413 bdevname(bd, buf)); 436 - if (ibd->ibd_flags & IBDF_HAS_UDEV_PATH) { 437 - bl += sprintf(b + bl, " UDEV PATH: %s\n", 414 + if (ibd->ibd_flags & IBDF_HAS_UDEV_PATH) 415 + bl += sprintf(b + bl, " UDEV PATH: %s", 438 416 ibd->ibd_udev_path); 439 - } else 440 - bl += sprintf(b + bl, "\n"); 417 + bl += sprintf(b + bl, " readonly: %d\n", ibd->ibd_readonly); 441 418 442 419 bl += sprintf(b + bl, " "); 443 420 if (bd) {
+1
drivers/target/target_core_iblock.h
··· 18 18 u32 ibd_flags; 19 19 struct bio_set *ibd_bio_set; 20 20 struct block_device *ibd_bd; 21 + bool ibd_readonly; 21 22 } ____cacheline_aligned; 22 23 23 24 #endif /* TARGET_CORE_IBLOCK_H */