~ubuntu-branches/debian/squeeze/multipath-tools/squeeze

« back to all changes in this revision

Viewing changes to path_priority/pp_rdac/pp_rdac.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Günther
  • Date: 2010-04-11 13:22:35 UTC
  • mfrom: (8.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100411132235-p0xdu9sy65mlx32z
Tags: 0.4.8+git0.761c66f-8
* [16268d8] Drop path from dmsetup_env call - thanks to Ferenc Wagner
* [2f3bdd5] Use $name in multipath.udev as well - thanks to Ferenc Wagner
  for testing
* [c978487] Don't pass -g on mips(el) to work around a binutils bug.  See
  http://sources.redhat.com/bugzilla/show_bug.cgi?id=10144 for details.
* [9daf438] Make sure we discover multipaths before checkfs/mountall runs
  This covers the cornercase where e.g. /home is on multipath (but not on
  LVM) and multipath-tols aren't started via initramfs. (Closes: #577172)
* [f7cc840] Bump standards version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <string.h>
4
 
#include <sys/types.h>
5
 
#include <sys/stat.h>
6
 
#include <unistd.h>
7
 
#include <fcntl.h>
8
 
#include <sys/ioctl.h>
9
 
#include <errno.h>
10
 
 
11
 
#include "../../libmultipath/sg_include.h"
12
 
 
13
 
#define INQUIRY_CMD     0x12
14
 
#define INQUIRY_CMDLEN  6
15
 
 
16
 
int rdac_prio(const char *dev)
17
 
{
18
 
        unsigned char sense_buffer[256];
19
 
        unsigned char sb[128];
20
 
        unsigned char inqCmdBlk[INQUIRY_CMDLEN] = {INQUIRY_CMD, 1, 0xC9, 0,
21
 
                                                sizeof(sb), 0};
22
 
        struct sg_io_hdr io_hdr;
23
 
        int ret = 0;
24
 
        int fd;
25
 
 
26
 
        fd = open(dev, O_RDWR|O_NONBLOCK);
27
 
 
28
 
        if (fd <= 0) {
29
 
                fprintf(stderr, "opening of the device failed.\n");
30
 
                goto out;
31
 
        }
32
 
 
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;
41
 
        io_hdr.sbp = sb;
42
 
        io_hdr.timeout = 60000;
43
 
        io_hdr.pack_id = 0;
44
 
        if (ioctl(fd, SG_IO, &io_hdr) < 0) {
45
 
                fprintf(stderr, "sending inquiry command failed\n");
46
 
                goto out;
47
 
        }
48
 
        if (io_hdr.info & SG_INFO_OK_MASK) {
49
 
                fprintf(stderr, "inquiry command indicates error");
50
 
                goto out;
51
 
        }
52
 
 
53
 
        close(fd);
54
 
        
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");
62
 
                goto out;
63
 
        }
64
 
        
65
 
        if ( /* Current Volume Path Bit */
66
 
                ( sense_buffer[8] & 0x01) == 0x01 ) {
67
 
                /* 
68
 
                 * This volume was owned by the controller receiving
69
 
                 * the inquiry command.
70
 
                 */
71
 
                ret |= 0x01;
72
 
        }
73
 
 
74
 
        /* Volume Preferred Path Priority */
75
 
        switch ( sense_buffer[9] & 0x0F ) {
76
 
        case 0x01:
77
 
                /* 
78
 
                 * Access to this volume is most preferred through
79
 
                 * this path and other paths with this value.
80
 
                 */
81
 
                ret |= 0x02;
82
 
                break;
83
 
        case 0x02:
84
 
                /*
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.
88
 
                 */
89
 
                /* Fallthrough */
90
 
        default:
91
 
                /* Reserved values */
92
 
                break;
93
 
        }
94
 
        
95
 
out:
96
 
        return(ret);
97
 
}
98
 
 
99
 
int
100
 
main (int argc, char **argv)
101
 
{
102
 
        int prio;
103
 
        if (argc != 2) {
104
 
                fprintf(stderr, "Wrong number of arguments.\n");
105
 
                fprintf(stderr, "Usage: %s device\n", argv[0]);
106
 
                prio = 0;
107
 
        } else
108
 
                prio = rdac_prio(argv[1]);
109
 
 
110
 
        printf("%d\n", prio);
111
 
        exit(0);
112
 
}