11
#include "../../libmultipath/sg_include.h"
13
#define INQUIRY_CMD 0x12
14
#define INQUIRY_CMDLEN 6
16
int rdac_prio(const char *dev)
18
unsigned char sense_buffer[256];
19
unsigned char sb[128];
20
unsigned char inqCmdBlk[INQUIRY_CMDLEN] = {INQUIRY_CMD, 1, 0xC9, 0,
22
struct sg_io_hdr io_hdr;
26
fd = open(dev, O_RDWR|O_NONBLOCK);
29
fprintf(stderr, "opening of the device failed.\n");
33
memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
34
io_hdr.interface_id = 'S';
35
io_hdr.cmd_len = sizeof (inqCmdBlk);
36
io_hdr.mx_sb_len = sizeof (sb);
37
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
38
io_hdr.dxfer_len = sizeof (sense_buffer);
39
io_hdr.dxferp = sense_buffer;
40
io_hdr.cmdp = inqCmdBlk;
42
io_hdr.timeout = 60000;
44
if (ioctl(fd, SG_IO, &io_hdr) < 0) {
45
fprintf(stderr, "sending inquiry command failed\n");
48
if (io_hdr.info & SG_INFO_OK_MASK) {
49
fprintf(stderr, "inquiry command indicates error");
55
if (/* Verify the code page - right page & page identifier */
56
sense_buffer[1] != 0xc9 ||
57
sense_buffer[3] != 0x2c ||
58
sense_buffer[4] != 'v' ||
59
sense_buffer[5] != 'a' ||
60
sense_buffer[6] != 'c' ) {
61
fprintf(stderr, "Volume access control page in unknown format");
65
if ( /* Current Volume Path Bit */
66
( sense_buffer[8] & 0x01) == 0x01 ) {
68
* This volume was owned by the controller receiving
69
* the inquiry command.
74
/* Volume Preferred Path Priority */
75
switch ( sense_buffer[9] & 0x0F ) {
78
* Access to this volume is most preferred through
79
* this path and other paths with this value.
85
* Access to this volume through this path is to be used
86
* as a secondary path. Typically this path would be used
87
* for fail-over situations.
100
main (int argc, char **argv)
104
fprintf(stderr, "Wrong number of arguments.\n");
105
fprintf(stderr, "Usage: %s device\n", argv[0]);
108
prio = rdac_prio(argv[1]);
110
printf("%d\n", prio);