[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 14 of 21 RESEND] blktap3/drivers: Introduce core tapdisk server
This patch copies from blktap2 the core of the tapdisk process, with most changes coming from blktap2.5. Also, it replaces the minor number with type:/path/to/file in function tapdisk_server_get_vbd as there is no minor number in blktap3. Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxx> diff --git a/tools/blktap2/drivers/tapdisk-server.c b/tools/blktap3/drivers/tapdisk-server.c copy from tools/blktap2/drivers/tapdisk-server.c copy to tools/blktap3/drivers/tapdisk-server.c --- a/tools/blktap2/drivers/tapdisk-server.c +++ b/tools/blktap3/drivers/tapdisk-server.c @@ -25,6 +25,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include <stdio.h> #include <errno.h> #include <unistd.h> @@ -32,18 +33,32 @@ #include <sys/ioctl.h> #include <sys/signal.h> -#include "tapdisk-utils.h" +#include "tapdisk-syslog.h" #include "tapdisk-server.h" #include "tapdisk-driver.h" #include "tapdisk-interface.h" +#include "tapdisk-log.h" #define DBG(_level, _f, _a...) tlog_write(_level, _f, ##_a) #define ERR(_err, _f, _a...) tlog_error(_err, _f, ##_a) - tapdisk_server_t server; +#define TAPDISK_TIOCBS (TAPDISK_DATA_REQUESTS + 50) + +typedef struct tapdisk_server { + int run; + + struct tqh_td_vbd_handle vbds; + scheduler_t scheduler; + struct tqueue aio_queue; + char *name; + char *ident; + int facility; +} tapdisk_server_t; + +static tapdisk_server_t server; #define tapdisk_server_for_each_vbd(vbd, tmp) \ - list_for_each_entry_safe(vbd, tmp, &server.vbds, next) + TAILQ_FOREACH_SAFE(vbd, &server.vbds, entry, tmp) td_image_t * tapdisk_server_get_shared_image(td_image_t *image) @@ -56,26 +71,26 @@ tapdisk_server_get_shared_image(td_image tapdisk_server_for_each_vbd(vbd, tmpv) tapdisk_vbd_for_each_image(vbd, img, tmpi) - if (img->type == image->type && - !strcmp(img->name, image->name)) + if (img->type == image->type && !strcmp(img->name, image->name)) return img; return NULL; } -struct list_head * -tapdisk_server_get_all_vbds(void) +struct tqh_td_vbd_handle *tapdisk_server_get_all_vbds(void) { return &server.vbds; } td_vbd_t * -tapdisk_server_get_vbd(uint16_t uuid) +tapdisk_server_get_vbd(const char *params) { td_vbd_t *vbd, *tmp; + assert(params); + tapdisk_server_for_each_vbd(vbd, tmp) - if (vbd->uuid == uuid) + if (!strcmp(vbd->name, params)) return vbd; return NULL; @@ -84,14 +99,13 @@ tapdisk_server_get_vbd(uint16_t uuid) void tapdisk_server_add_vbd(td_vbd_t *vbd) { - list_add_tail(&vbd->next, &server.vbds); + TAILQ_INSERT_TAIL(&server.vbds, vbd, entry); } void tapdisk_server_remove_vbd(td_vbd_t *vbd) { - list_del(&vbd->next); - INIT_LIST_HEAD(&vbd->next); + TAILQ_REMOVE(&server.vbds, vbd, entry); tapdisk_server_check_state(); } @@ -111,13 +125,14 @@ tapdisk_server_debug(void) tapdisk_server_for_each_vbd(vbd, tmp) tapdisk_vbd_debug(vbd); - tlog_flush(); + DBG(TLOG_INFO, "debug log completed\n"); + tlog_precious(); } void tapdisk_server_check_state(void) { - if (list_empty(&server.vbds)) + if (TAILQ_EMPTY(&server.vbds)) server.run = 0; } @@ -136,7 +151,12 @@ tapdisk_server_unregister_event(event_id } void -tapdisk_server_set_max_timeout(int seconds) +tapdisk_server_mask_event(event_id_t event, int masked) +{ + return scheduler_mask_event(&server.scheduler, event, masked); +} + +void tapdisk_server_set_max_timeout(int seconds) { scheduler_set_max_timeout(&server.scheduler, seconds); } @@ -180,7 +200,6 @@ tapdisk_server_submit_tiocbs(void) static void tapdisk_server_kick_responses(void) { - int n; td_vbd_t *vbd, *tmp; tapdisk_server_for_each_vbd(vbd, tmp) @@ -196,8 +215,19 @@ tapdisk_server_check_vbds(void) tapdisk_vbd_check_state(vbd); } -static void -tapdisk_server_stop_vbds(void) +static int +tapdisk_server_recheck_vbds(void) +{ + td_vbd_t *vbd, *tmp; + int rv = 0; + + tapdisk_server_for_each_vbd(vbd, tmp) + rv += tapdisk_vbd_recheck_state(vbd); + + return rv; +} + +static void tapdisk_server_stop_vbds(void) { td_vbd_t *vbd, *tmp; @@ -218,9 +248,49 @@ tapdisk_server_close_aio(void) tapdisk_free_queue(&server.aio_queue); } -static void -tapdisk_server_close(void) +int tapdisk_server_openlog(const char *name, int options, int facility) { + server.facility = facility; + server.name = strdup(name); + server.ident = tapdisk_syslog_ident(name); + + if (!server.name || !server.ident) + return -errno; + + openlog(server.ident, options, facility); + + return 0; +} + +void tapdisk_server_closelog(void) +{ + closelog(); + + free(server.name); + server.name = NULL; + + free(server.ident); + server.ident = NULL; +} + +static int tapdisk_server_open_tlog(void) +{ + int err = 0; + + if (server.name) + err = tlog_open(server.name, server.facility, TLOG_WARN); + + return err; +} + +static void tapdisk_server_close_tlog(void) +{ + tlog_close(); +} + +static void tapdisk_server_close(void) +{ + tapdisk_server_close_tlog(); tapdisk_server_close_aio(); } @@ -238,8 +308,12 @@ tapdisk_server_iterate(void) DBG(TLOG_WARN, "server wait returned %d\n", ret); tapdisk_server_check_vbds(); - tapdisk_server_submit_tiocbs(); - tapdisk_server_kick_responses(); + do { + tapdisk_server_submit_tiocbs(); + tapdisk_server_kick_responses(); + + ret = tapdisk_server_recheck_vbds(); + } while (ret); } static void @@ -272,6 +346,7 @@ tapdisk_server_signal_handler(int signal break; case SIGUSR1: + DBG(TLOG_INFO, "debugging on signal %d\n", signal); tapdisk_server_debug(); break; } @@ -281,7 +356,7 @@ int tapdisk_server_init(void) { memset(&server, 0, sizeof(server)); - INIT_LIST_HEAD(&server.vbds); + TAILQ_INIT(&server.vbds); scheduler_initialize(&server.scheduler); @@ -297,17 +372,23 @@ tapdisk_server_complete(void) if (err) goto fail; + err = tapdisk_server_open_tlog(); + if (err) + goto fail; + server.run = 1; return 0; fail: + tapdisk_server_close_tlog(); tapdisk_server_close_aio(); return err; } int -tapdisk_server_initialize(void) +tapdisk_server_initialize(const char *read __attribute__((unused)), + const char *write __attribute__((unused))) { int err; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |