chiark / gitweb /
[PATCH] extras multipath update
[elogind.git] / extras / multipath / unused.c
1 static int
2 do_tur(int fd)
3 {
4         unsigned char turCmdBlk[TUR_CMD_LEN] = { 0x00, 0, 0, 0, 0, 0 };
5         struct sg_io_hdr io_hdr;
6         unsigned char sense_buffer[32];
7
8         memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
9         io_hdr.interface_id = 'S';
10         io_hdr.cmd_len = sizeof (turCmdBlk);
11         io_hdr.mx_sb_len = sizeof (sense_buffer);
12         io_hdr.dxfer_direction = SG_DXFER_NONE;
13         io_hdr.cmdp = turCmdBlk;
14         io_hdr.sbp = sense_buffer;
15         io_hdr.timeout = 20000;
16         io_hdr.pack_id = 0;
17         if (ioctl(fd, SG_IO, &io_hdr) < 0) {
18                 close(fd);
19                 return 0;
20         }
21         if (io_hdr.info & SG_INFO_OK_MASK) {
22                 return 0;
23         }
24         return 1;
25 }
26
27 static int
28 del_map(char * str) {
29         struct dm_task *dmt;
30
31         if (!(dmt = dm_task_create(DM_DEVICE_REMOVE)))
32                 return 0;
33         if (!dm_task_set_name(dmt, str))
34                 goto delout;
35         if (!dm_task_run(dmt))
36                 goto delout;
37
38         printf("Deleted device map : %s\n", str);
39
40         delout:
41         dm_task_destroy(dmt);
42         return 1;
43 }
44
45 get_table(const char * str)
46 {
47         int r = 0;
48         struct dm_task *dmt;
49         void *next = NULL;
50         uint64_t start, length;
51         char *target_type = NULL;
52         char *params;
53
54         if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
55                 return 0;
56
57         if (!dm_task_set_name(dmt, str))
58                 goto out;
59
60         if (!dm_task_run(dmt))
61                 goto out;
62
63         do {
64                 next = dm_get_next_target(dmt, next, &start, &length,
65                                           &target_type, &params);
66                 if (target_type) {
67                         printf("%" PRIu64 " %" PRIu64 " %s %s\n",
68                                start, length, target_type, params);
69                 }
70         } while (next);
71
72         r = 1;
73
74       out:
75         dm_task_destroy(dmt);
76         return r;
77
78 }