Skip to content

Commit 01e5f6a

Browse files
committed
lib: allow block device file use for tests
Allow using a block device file to be specified for running tests by suppressing the block backend driver when opening the device. Doing so, the block device file will be used to pass either SCSI or ATA commands to the disk using the SCSI or ATA backends. Signed-off-by: Damien Le Moal <[email protected]>
1 parent 1c79cb2 commit 01e5f6a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/zbc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,20 @@ int zbc_open(const char *filename, int flags, struct zbc_device **pdev)
340340
struct zbc_device *dev = NULL;
341341
unsigned int allowed_drv;
342342
char *path = NULL;
343-
int ret, i;
343+
int ret, i, mask = ZBC_O_DRV_MASK;
344344

345345
ret = zbc_realpath(filename, &path);
346346
if (ret)
347347
return ret;
348348

349-
allowed_drv = flags & ZBC_O_DRV_MASK;
349+
#ifdef HAVE_DEVTEST
350+
if (flags & ZBC_O_DEVTEST)
351+
mask = ZBC_O_TEST_DRV_MASK;
352+
#endif
353+
354+
allowed_drv = flags & mask;
350355
if (!allowed_drv)
351-
allowed_drv = ZBC_O_DRV_MASK;
356+
allowed_drv = mask;
352357

353358
/* Test all backends until one accepts the drive */
354359
ret = -ENODEV;

lib/zbc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static inline void zbc_set_errno(enum zbc_sk sk, enum zbc_asc_ascq asc_ascq)
175175
#define ZBC_O_DMODE_MASK (ZBC_O_MODE_MASK | O_DIRECT)
176176
#define ZBC_O_DRV_MASK (ZBC_O_DRV_BLOCK | ZBC_O_DRV_SCSI | \
177177
ZBC_O_DRV_ATA | ZBC_O_DRV_FAKE)
178+
#define ZBC_O_TEST_DRV_MASK (ZBC_O_DRV_SCSI | ZBC_O_DRV_ATA | \
179+
ZBC_O_DRV_FAKE)
178180

179181
/**
180182
* Test if a device is in test mode.

0 commit comments

Comments
 (0)