ia64/xen-unstable

view tools/blktap/drivers/blktapctrl.c @ 14105:e9bd3267ff23

[TAPDISK] honor read-only attributes when creating tap-based VBDs
Signed-off-by: Jake Wires <jwires@xensource.com>
author Jake Wires <jwires@xensource.com>
date Fri Feb 23 17:26:07 2007 -0800 (2007-02-23)
parents d2f12edc10ee
children f033cc5cc0d5
line source
1 /*
2 * blktapctrl.c
3 *
4 * userspace controller for the blktap disks.
5 * As requests for new block devices arrive,
6 * the controller spawns off a separate process
7 * per-disk.
8 *
9 *
10 * Copyright (c) 2005 Julian Chesterfield and Andrew Warfield.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation; or, when distributed
15 * separately from the Linux kernel or incorporated into other
16 * software packages, subject to the following license:
17 *
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this source file (the "Software"), to deal in the Software without
20 * restriction, including without limitation the rights to use, copy, modify,
21 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
22 * and to permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34 * IN THE SOFTWARE.
35 */
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <sys/mman.h>
40 #include <sys/user.h>
41 #include <err.h>
42 #include <errno.h>
43 #include <sys/types.h>
44 #include <linux/types.h>
45 #include <signal.h>
46 #include <fcntl.h>
47 #include <sys/poll.h>
48 #include <sys/ioctl.h>
49 #include <string.h>
50 #include <unistd.h>
51 #include <xs.h>
52 #include <printf.h>
53 #include <sys/time.h>
54 #include <syslog.h>
56 #include "blktaplib.h"
57 #include "blktapctrl.h"
58 #include "tapdisk.h"
60 #define PIDFILE "/var/run/blktapctrl.pid"
62 #define NUM_POLL_FDS 2
63 #define MSG_SIZE 4096
64 #define MAX_TIMEOUT 10
65 #define MAX_RAND_VAL 0xFFFF
66 #define MAX_ATTEMPTS 10
68 int run = 1;
69 int max_timeout = MAX_TIMEOUT;
70 int ctlfd = 0;
72 int blktap_major;
74 static int open_ctrl_socket(char *devname);
75 static int write_msg(int fd, int msgtype, void *ptr, void *ptr2);
76 static int read_msg(int fd, int msgtype, void *ptr);
77 static driver_list_entry_t *active_disks[MAX_DISK_TYPES];
79 static void init_driver_list(void)
80 {
81 int i;
83 for (i = 0; i < MAX_DISK_TYPES; i++)
84 active_disks[i] = NULL;
85 return;
86 }
88 static void init_rng(void)
89 {
90 static uint32_t seed;
91 struct timeval tv;
93 gettimeofday(&tv, NULL);
94 seed = tv.tv_usec;
95 srand48(seed);
96 return;
97 }
99 static void make_blktap_dev(char *devname, int major, int minor)
100 {
101 struct stat st;
103 if (lstat(devname, &st) != 0) {
104 /*Need to create device*/
105 if (mkdir(BLKTAP_DEV_DIR, 0755) == 0)
106 DPRINTF("Created %s directory\n",BLKTAP_DEV_DIR);
107 if (mknod(devname, S_IFCHR|0600,
108 makedev(major, minor)) == 0)
109 DPRINTF("Created %s device\n",devname);
110 } else {
111 DPRINTF("%s device already exists\n",devname);
112 /* it already exists, but is it the same major number */
113 if (((st.st_rdev>>8) & 0xff) != major) {
114 DPRINTF("%s has old major %d\n",
115 devname,
116 (unsigned int)((st.st_rdev >> 8) & 0xff));
117 /* only try again if we succed in deleting it */
118 if (!unlink(devname))
119 make_blktap_dev(devname, major, minor);
120 }
121 }
122 }
124 static int get_new_dev(int *major, int *minor, blkif_t *blkif)
125 {
126 domid_translate_t tr;
127 int ret;
128 char *devname;
130 tr.domid = blkif->domid;
131 tr.busid = (unsigned short)blkif->be_id;
132 ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF, tr );
134 if ( (ret <= 0)||(ret > MAX_TAP_DEV) ) {
135 DPRINTF("Incorrect Dev ID [%d]\n",ret);
136 return -1;
137 }
139 *minor = ret;
140 *major = ioctl(ctlfd, BLKTAP_IOCTL_MAJOR, ret );
141 if (*major < 0) {
142 DPRINTF("Incorrect Major ID [%d]\n",*major);
143 return -1;
144 }
146 asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, *minor);
147 make_blktap_dev(devname,*major,*minor);
148 DPRINTF("Received device id %d and major %d, "
149 "sent domid %d and be_id %d\n",
150 *minor, *major, tr.domid, tr.busid);
151 return 0;
152 }
154 static int get_tapdisk_pid(blkif_t *blkif)
155 {
156 int ret;
158 if ((ret = write_msg(blkif->fds[WRITE], CTLMSG_PID, blkif, NULL))
159 <= 0) {
160 DPRINTF("Write_msg failed - CTLMSG_PID(%d)\n", ret);
161 return -EINVAL;
162 }
164 if ((ret = read_msg(blkif->fds[READ], CTLMSG_PID_RSP, blkif))
165 <= 0) {
166 DPRINTF("Read_msg failure - CTLMSG_PID(%d)\n", ret);
167 return -EINVAL;
168 }
169 return 1;
170 }
172 /* Look up the disk specified by path:
173 * if found, dev points to the device string in the path
174 * type is the tapdisk driver type id
175 * blkif is the existing interface if this is a shared driver
176 * and NULL otherwise.
177 * return 0 on success, -1 on error.
178 */
180 static int test_path(char *path, char **dev, int *type, blkif_t *blkif)
181 {
182 char *ptr, handle[10];
183 int i, size, found = 0;
185 size = sizeof(dtypes)/sizeof(disk_info_t *);
186 *type = MAX_DISK_TYPES + 1;
187 blkif = NULL;
189 if ( (ptr = strstr(path, ":"))!=NULL) {
190 memcpy(handle, path, (ptr - path));
191 *dev = ptr + 1;
192 ptr = handle + (ptr - path);
193 *ptr = '\0';
194 DPRINTF("Detected handle: [%s]\n",handle);
196 for (i = 0; i < size; i++)
197 if (strncmp(handle, dtypes[i]->handle,
198 (ptr - path)) ==0) {
199 found = 1;
200 break;
201 }
203 if (found) {
204 *type = dtypes[i]->idnum;
206 if (dtypes[i]->single_handler == 1) {
207 /* Check whether tapdisk process
208 already exists */
209 if (active_disks[dtypes[i]->idnum] == NULL)
210 blkif = NULL;
211 else
212 blkif = active_disks[dtypes[i]
213 ->idnum]->blkif;
214 }
215 return 0;
216 }
217 }
219 /* Fall-through case, we didn't find a disk driver. */
220 DPRINTF("Unknown blktap disk type [%s]!\n",handle);
221 *dev = NULL;
222 return -1;
223 }
226 static void add_disktype(blkif_t *blkif, int type)
227 {
228 driver_list_entry_t *entry, **pprev;
230 if (type > MAX_DISK_TYPES)
231 return;
233 entry = malloc(sizeof(driver_list_entry_t));
234 entry->blkif = blkif;
235 entry->next = NULL;
237 pprev = &active_disks[type];
238 while (*pprev != NULL)
239 pprev = &(*pprev)->next;
241 *pprev = entry;
242 entry->pprev = pprev;
243 }
245 static int del_disktype(blkif_t *blkif)
246 {
247 driver_list_entry_t *entry, **pprev;
248 int type = blkif->drivertype, count = 0, close = 0;
250 if (type > MAX_DISK_TYPES)
251 return 1;
253 pprev = &active_disks[type];
254 while ((*pprev != NULL) && ((*pprev)->blkif != blkif))
255 pprev = &(*pprev)->next;
257 if ((entry = *pprev) == NULL) {
258 DPRINTF("DEL_DISKTYPE: No match\n");
259 return 1;
260 }
262 *pprev = entry->next;
263 if (entry->next)
264 entry->next->pprev = pprev;
266 DPRINTF("DEL_DISKTYPE: Freeing entry\n");
267 free(entry);
269 /* Caller should close() if no single controller, or list is empty. */
270 return (!dtypes[type]->single_handler || (active_disks[type] == NULL));
271 }
273 static int write_msg(int fd, int msgtype, void *ptr, void *ptr2)
274 {
275 blkif_t *blkif;
276 blkif_info_t *blk;
277 msg_hdr_t *msg;
278 msg_newdev_t *msg_dev;
279 char *p, *buf, *path;
280 int msglen, len, ret;
281 fd_set writefds;
282 struct timeval timeout;
283 image_t *image, *img;
284 uint32_t seed;
286 blkif = (blkif_t *)ptr;
287 blk = blkif->info;
288 image = blkif->prv;
289 len = 0;
291 switch (msgtype)
292 {
293 case CTLMSG_PARAMS:
294 path = (char *)ptr2;
295 DPRINTF("Write_msg called: CTLMSG_PARAMS, sending [%s, %s]\n",
296 blk->params, path);
298 msglen = sizeof(msg_hdr_t) + strlen(path) + 1;
299 buf = malloc(msglen);
301 /*Assign header fields*/
302 msg = (msg_hdr_t *)buf;
303 msg->type = CTLMSG_PARAMS;
304 msg->len = msglen;
305 msg->drivertype = blkif->drivertype;
306 msg->readonly = blkif->readonly;
308 gettimeofday(&timeout, NULL);
309 msg->cookie = blkif->cookie;
310 DPRINTF("Generated cookie, %d\n",blkif->cookie);
312 /*Copy blk->params to msg*/
313 p = buf + sizeof(msg_hdr_t);
314 memcpy(p, path, strlen(path) + 1);
316 break;
318 case CTLMSG_NEWDEV:
319 DPRINTF("Write_msg called: CTLMSG_NEWDEV\n");
321 msglen = sizeof(msg_hdr_t) + sizeof(msg_newdev_t);
322 buf = malloc(msglen);
324 /*Assign header fields*/
325 msg = (msg_hdr_t *)buf;
326 msg->type = CTLMSG_NEWDEV;
327 msg->len = msglen;
328 msg->drivertype = blkif->drivertype;
329 msg->cookie = blkif->cookie;
331 msg_dev = (msg_newdev_t *)(buf + sizeof(msg_hdr_t));
332 msg_dev->devnum = blkif->minor;
333 msg_dev->domid = blkif->domid;
335 break;
337 case CTLMSG_CLOSE:
338 DPRINTF("Write_msg called: CTLMSG_CLOSE\n");
340 msglen = sizeof(msg_hdr_t);
341 buf = malloc(msglen);
343 /*Assign header fields*/
344 msg = (msg_hdr_t *)buf;
345 msg->type = CTLMSG_CLOSE;
346 msg->len = msglen;
347 msg->drivertype = blkif->drivertype;
348 msg->cookie = blkif->cookie;
350 break;
352 case CTLMSG_PID:
353 DPRINTF("Write_msg called: CTLMSG_PID\n");
355 msglen = sizeof(msg_hdr_t);
356 buf = malloc(msglen);
358 /*Assign header fields*/
359 msg = (msg_hdr_t *)buf;
360 msg->type = CTLMSG_PID;
361 msg->len = msglen;
362 msg->drivertype = blkif->drivertype;
363 msg->cookie = blkif->cookie;
365 break;
367 default:
368 return -1;
369 }
371 /*Now send the message*/
372 ret = 0;
373 FD_ZERO(&writefds);
374 FD_SET(fd,&writefds);
375 timeout.tv_sec = max_timeout; /*Wait for up to max_timeout seconds*/
376 timeout.tv_usec = 0;
377 if (select(fd+1, (fd_set *) 0, &writefds,
378 (fd_set *) 0, &timeout) > 0) {
379 len = write(fd, buf, msglen);
380 if (len == -1) DPRINTF("Write failed: (%d)\n",errno);
381 }
382 free(buf);
384 return len;
385 }
387 static int read_msg(int fd, int msgtype, void *ptr)
388 {
389 blkif_t *blkif;
390 blkif_info_t *blk;
391 msg_hdr_t *msg;
392 msg_pid_t *msg_pid;
393 char *p, *buf;
394 int msglen = MSG_SIZE, len, ret;
395 fd_set readfds;
396 struct timeval timeout;
397 image_t *image, *img;
400 blkif = (blkif_t *)ptr;
401 blk = blkif->info;
402 image = blkif->prv;
404 buf = malloc(MSG_SIZE);
406 ret = 0;
407 FD_ZERO(&readfds);
408 FD_SET(fd,&readfds);
409 timeout.tv_sec = max_timeout; /*Wait for up to max_timeout seconds*/
410 timeout.tv_usec = 0;
411 if (select(fd+1, &readfds, (fd_set *) 0,
412 (fd_set *) 0, &timeout) > 0) {
413 ret = read(fd, buf, msglen);
414 }
415 if (ret > 0) {
416 msg = (msg_hdr_t *)buf;
417 switch (msg->type)
418 {
419 case CTLMSG_IMG:
420 img = (image_t *)(buf + sizeof(msg_hdr_t));
421 image->size = img->size;
422 image->secsize = img->secsize;
423 image->info = img->info;
425 DPRINTF("Received CTLMSG_IMG: %llu, %lu, %u\n",
426 image->size, image->secsize, image->info);
427 if(msgtype != CTLMSG_IMG) ret = 0;
428 break;
430 case CTLMSG_IMG_FAIL:
431 DPRINTF("Received CTLMSG_IMG_FAIL, "
432 "unable to open image\n");
433 ret = 0;
434 break;
436 case CTLMSG_NEWDEV_RSP:
437 DPRINTF("Received CTLMSG_NEWDEV_RSP\n");
438 if(msgtype != CTLMSG_NEWDEV_RSP) ret = 0;
439 break;
441 case CTLMSG_NEWDEV_FAIL:
442 DPRINTF("Received CTLMSG_NEWDEV_FAIL\n");
443 ret = 0;
444 break;
446 case CTLMSG_CLOSE_RSP:
447 DPRINTF("Received CTLMSG_CLOSE_RSP\n");
448 if (msgtype != CTLMSG_CLOSE_RSP) ret = 0;
449 break;
451 case CTLMSG_PID_RSP:
452 DPRINTF("Received CTLMSG_PID_RSP\n");
453 if (msgtype != CTLMSG_PID_RSP) ret = 0;
454 else {
455 msg_pid = (msg_pid_t *)
456 (buf + sizeof(msg_hdr_t));
457 blkif->tappid = msg_pid->pid;
458 DPRINTF("\tPID: [%d]\n",blkif->tappid);
459 }
460 break;
461 default:
462 DPRINTF("UNKNOWN MESSAGE TYPE RECEIVED\n");
463 ret = 0;
464 break;
465 }
466 }
468 free(buf);
470 return ret;
472 }
474 int blktapctrl_new_blkif(blkif_t *blkif)
475 {
476 blkif_info_t *blk;
477 int major, minor, fd_read, fd_write, type, new;
478 char *rdctldev, *wrctldev, *cmd, *ptr;
479 image_t *image;
480 blkif_t *exist = NULL;
482 DPRINTF("Received a poll for a new vbd\n");
483 if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
484 if (get_new_dev(&major, &minor, blkif)<0)
485 return -1;
487 if (test_path(blk->params, &ptr, &type, exist) != 0) {
488 DPRINTF("Error in blktap device string(%s).\n",
489 blk->params);
490 return -1;
491 }
492 blkif->drivertype = type;
493 blkif->cookie = lrand48() % MAX_RAND_VAL;
495 if (!exist) {
496 DPRINTF("Process does not exist:\n");
497 asprintf(&rdctldev, "/dev/xen/tapctrlread%d", minor);
498 blkif->fds[READ] = open_ctrl_socket(rdctldev);
501 asprintf(&wrctldev, "/dev/xen/tapctrlwrite%d", minor);
502 blkif->fds[WRITE] = open_ctrl_socket(wrctldev);
504 if (blkif->fds[READ] == -1 || blkif->fds[WRITE] == -1)
505 goto fail;
507 /*launch the new process*/
508 asprintf(&cmd, "tapdisk %s %s", wrctldev, rdctldev);
509 DPRINTF("Launching process, CMDLINE [%s]\n",cmd);
510 if (system(cmd) == -1) {
511 DPRINTF("Unable to fork, cmdline: [%s]\n",cmd);
512 return -1;
513 }
515 free(rdctldev);
516 free(wrctldev);
517 free(cmd);
518 } else {
519 DPRINTF("Process exists!\n");
520 blkif->fds[READ] = exist->fds[READ];
521 blkif->fds[WRITE] = exist->fds[WRITE];
522 }
524 add_disktype(blkif, type);
525 blkif->major = major;
526 blkif->minor = minor;
528 image = (image_t *)malloc(sizeof(image_t));
529 blkif->prv = (void *)image;
530 blkif->ops = &tapdisk_ops;
532 /*Retrieve the PID of the new process*/
533 if (get_tapdisk_pid(blkif) <= 0) {
534 DPRINTF("Unable to contact disk process\n");
535 goto fail;
536 }
538 /* Both of the following read and write calls will block up to
539 * max_timeout val*/
540 if (write_msg(blkif->fds[WRITE], CTLMSG_PARAMS, blkif, ptr)
541 <= 0) {
542 DPRINTF("Write_msg failed - CTLMSG_PARAMS\n");
543 goto fail;
544 }
546 if (read_msg(blkif->fds[READ], CTLMSG_IMG, blkif) <= 0) {
547 DPRINTF("Read_msg failure - CTLMSG_IMG\n");
548 goto fail;
549 }
551 } else return -1;
553 return 0;
554 fail:
555 ioctl(ctlfd, BLKTAP_IOCTL_FREEINTF, minor);
556 return -EINVAL;
557 }
559 int map_new_blktapctrl(blkif_t *blkif)
560 {
561 DPRINTF("Received a poll for a new devmap\n");
562 if (write_msg(blkif->fds[WRITE], CTLMSG_NEWDEV, blkif, NULL) <= 0) {
563 DPRINTF("Write_msg failed - CTLMSG_NEWDEV\n");
564 return -EINVAL;
565 }
567 if (read_msg(blkif->fds[READ], CTLMSG_NEWDEV_RSP, blkif) <= 0) {
568 DPRINTF("Read_msg failed - CTLMSG_NEWDEV_RSP\n");
569 return -EINVAL;
570 }
571 DPRINTF("Exiting map_new_blktapctrl\n");
573 return blkif->minor - 1;
574 }
576 int unmap_blktapctrl(blkif_t *blkif)
577 {
578 DPRINTF("Unmapping vbd\n");
580 if (write_msg(blkif->fds[WRITE], CTLMSG_CLOSE, blkif, NULL) <= 0) {
581 DPRINTF("Write_msg failed - CTLMSG_CLOSE\n");
582 return -EINVAL;
583 }
585 if (del_disktype(blkif)) {
586 close(blkif->fds[WRITE]);
587 close(blkif->fds[READ]);
588 }
590 return 0;
591 }
593 int open_ctrl_socket(char *devname)
594 {
595 int ret;
596 int ipc_fd;
597 char *cmd;
598 fd_set socks;
599 struct timeval timeout;
601 ret = mkfifo(devname,S_IRWXU|S_IRWXG|S_IRWXO);
602 if ( (ret != 0) && (errno != EEXIST) ) {
603 DPRINTF("ERROR: pipe failed (%d)\n", errno);
604 exit(0);
605 }
607 ipc_fd = open(devname,O_RDWR|O_NONBLOCK);
609 if (ipc_fd < 0) {
610 DPRINTF("FD open failed\n");
611 return -1;
612 }
614 return ipc_fd;
615 }
617 static void print_drivers(void)
618 {
619 int i, size;
621 size = sizeof(dtypes)/sizeof(disk_info_t *);
622 DPRINTF("blktapctrl: v1.0.0\n");
623 for (i = 0; i < size; i++)
624 DPRINTF("Found driver: [%s]\n",dtypes[i]->name);
625 }
627 static void write_pidfile(long pid)
628 {
629 char buf[100];
630 int len;
631 int fd;
632 int flags;
634 fd = open(PIDFILE, O_RDWR | O_CREAT, 0600);
635 if (fd == -1) {
636 DPRINTF("Opening pid file failed (%d)\n", errno);
637 exit(1);
638 }
640 /* We exit silently if daemon already running. */
641 if (lockf(fd, F_TLOCK, 0) == -1)
642 exit(0);
644 /* Set FD_CLOEXEC, so that tapdisk doesn't get this file
645 descriptor. */
646 if ((flags = fcntl(fd, F_GETFD)) == -1) {
647 DPRINTF("F_GETFD failed (%d)\n", errno);
648 exit(1);
649 }
650 flags |= FD_CLOEXEC;
651 if (fcntl(fd, F_SETFD, flags) == -1) {
652 DPRINTF("F_SETFD failed (%d)\n", errno);
653 exit(1);
654 }
656 len = sprintf(buf, "%ld\n", pid);
657 if (write(fd, buf, len) != len) {
658 DPRINTF("Writing pid file failed (%d)\n", errno);
659 exit(1);
660 }
661 }
663 int main(int argc, char *argv[])
664 {
665 char *devname;
666 tapdev_info_t *ctlinfo;
667 int tap_pfd, store_pfd, xs_fd, ret, timeout, pfd_count, count=0;
668 struct xs_handle *h;
669 struct pollfd pfd[NUM_POLL_FDS];
670 pid_t process;
671 char buf[128];
673 __init_blkif();
674 snprintf(buf, sizeof(buf), "BLKTAPCTRL[%d]", getpid());
675 openlog(buf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
676 daemon(0,0);
678 print_drivers();
679 init_driver_list();
680 init_rng();
682 register_new_blkif_hook(blktapctrl_new_blkif);
683 register_new_devmap_hook(map_new_blktapctrl);
684 register_new_unmap_hook(unmap_blktapctrl);
686 /* Attach to blktap0 */
687 asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME);
688 if ((ret = xc_find_device_number("blktap0")) < 0)
689 goto open_failed;
690 blktap_major = major(ret);
691 make_blktap_dev(devname,blktap_major,0);
692 ctlfd = open(devname, O_RDWR);
693 if (ctlfd == -1) {
694 DPRINTF("blktap0 open failed\n");
695 goto open_failed;
696 }
699 retry:
700 /* Set up store connection and watch. */
701 h = xs_daemon_open();
702 if (h == NULL) {
703 DPRINTF("xs_daemon_open failed -- "
704 "is xenstore running?\n");
705 if (count < MAX_ATTEMPTS) {
706 count++;
707 sleep(2);
708 goto retry;
709 } else goto open_failed;
710 }
712 ret = setup_probe_watch(h);
713 if (ret != 0) {
714 DPRINTF("Failed adding device probewatch\n");
715 xs_daemon_close(h);
716 goto open_failed;
717 }
719 ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
721 process = getpid();
722 write_pidfile(process);
723 ret = ioctl(ctlfd, BLKTAP_IOCTL_SENDPID, process );
725 /*Static pollhooks*/
726 pfd_count = 0;
727 tap_pfd = pfd_count++;
728 pfd[tap_pfd].fd = ctlfd;
729 pfd[tap_pfd].events = POLLIN;
731 store_pfd = pfd_count++;
732 pfd[store_pfd].fd = xs_fileno(h);
733 pfd[store_pfd].events = POLLIN;
735 while (run) {
736 timeout = 1000; /*Milliseconds*/
737 ret = poll(pfd, pfd_count, timeout);
739 if (ret > 0) {
740 if (pfd[store_pfd].revents) {
741 ret = xs_fire_next_watch(h);
742 }
743 }
744 }
746 xs_daemon_close(h);
747 ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_PASSTHROUGH );
748 close(ctlfd);
749 closelog();
751 return 0;
753 open_failed:
754 DPRINTF("Unable to start blktapctrl\n");
755 closelog();
756 return -1;
757 }
759 /*
760 * Local variables:
761 * c-file-style: "linux"
762 * indent-tabs-mode: t
763 * c-indent-level: 8
764 * c-basic-offset: 8
765 * tab-width: 8
766 * End:
767 */