[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 14/29] xl: split out block related code
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/xl/Makefile | 2 +- tools/xl/xl_block.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/xl/xl_cmdimpl.c | 99 -------------------------------------- 3 files changed, 130 insertions(+), 100 deletions(-) create mode 100644 tools/xl/xl_block.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index b31ec052c1..331ae21293 100644 --- a/tools/xl/Makefile +++ b/tools/xl/Makefile @@ -17,7 +17,7 @@ CFLAGS_XL += -Wshadow XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o xl_sxp.o xl_utils.o XL_OBJS += xl_tmem.o xl_parse.o xl_cpupool.o xl_flask.o -XL_OBJS += xl_vtpm.o +XL_OBJS += xl_vtpm.o xl_block.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL) diff --git a/tools/xl/xl_block.c b/tools/xl/xl_block.c new file mode 100644 index 0000000000..b0d79931f9 --- /dev/null +++ b/tools/xl/xl_block.c @@ -0,0 +1,129 @@ +/* + * Copyright 2009-2017 Citrix Ltd and other contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include <stdlib.h> + +#include <libxl.h> +#include <libxl_utils.h> +#include <libxlutil.h> + +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_blockattach(int argc, char **argv) +{ + int opt; + uint32_t fe_domid; + libxl_device_disk disk; + XLU_Config *config = 0; + + SWITCH_FOREACH_OPT(opt, "", NULL, "block-attach", 2) { + /* No options */ + } + + if (libxl_domain_qualifier_to_domid(ctx, argv[optind], &fe_domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]); + return 1; + } + optind++; + + parse_disk_config_multistring + (&config, argc-optind, (const char* const*)argv + optind, &disk); + + if (dryrun_only) { + char *json = libxl_device_disk_to_json(ctx, &disk); + printf("disk: %s\n", json); + free(json); + if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); } + return 0; + } + + if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) { + fprintf(stderr, "libxl_device_disk_add failed.\n"); + return 1; + } + return 0; +} + +int main_blocklist(int argc, char **argv) +{ + int opt; + int i, nb; + libxl_device_disk *disks; + libxl_diskinfo diskinfo; + + SWITCH_FOREACH_OPT(opt, "", NULL, "block-list", 1) { + /* No options */ + } + + printf("%-5s %-3s %-6s %-5s %-6s %-8s %-30s\n", + "Vdev", "BE", "handle", "state", "evt-ch", "ring-ref", "BE-path"); + for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) { + uint32_t domid; + if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", *argv); + continue; + } + disks = libxl_device_disk_list(ctx, domid, &nb); + if (!disks) { + continue; + } + for (i=0; i<nb; i++) { + if (!libxl_device_disk_getinfo(ctx, domid, &disks[i], &diskinfo)) { + /* Vdev BE hdl st evch rref BE-path*/ + printf("%-5d %-3d %-6d %-5d %-6d %-8d %-30s\n", + diskinfo.devid, diskinfo.backend_id, diskinfo.frontend_id, + diskinfo.state, diskinfo.evtch, diskinfo.rref, diskinfo.backend); + libxl_diskinfo_dispose(&diskinfo); + } + libxl_device_disk_dispose(&disks[i]); + } + free(disks); + } + return 0; +} + +int main_blockdetach(int argc, char **argv) +{ + uint32_t domid; + int opt, rc = 0; + libxl_device_disk disk; + + SWITCH_FOREACH_OPT(opt, "", NULL, "block-detach", 2) { + /* No options */ + } + + domid = xfind_domain(argv[optind]); + + if (libxl_vdev_to_device_disk(ctx, domid, argv[optind+1], &disk)) { + fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); + return 1; + } + rc = libxl_device_disk_remove(ctx, domid, &disk, 0); + if (rc) { + fprintf(stderr, "libxl_device_disk_remove failed.\n"); + return 1; + } + libxl_device_disk_dispose(&disk); + return rc; +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/xl/xl_cmdimpl.c b/tools/xl/xl_cmdimpl.c index aeb4fb362f..56524fe707 100644 --- a/tools/xl/xl_cmdimpl.c +++ b/tools/xl/xl_cmdimpl.c @@ -5176,105 +5176,6 @@ int main_channellist(int argc, char **argv) return 0; } -int main_blockattach(int argc, char **argv) -{ - int opt; - uint32_t fe_domid; - libxl_device_disk disk; - XLU_Config *config = 0; - - SWITCH_FOREACH_OPT(opt, "", NULL, "block-attach", 2) { - /* No options */ - } - - if (libxl_domain_qualifier_to_domid(ctx, argv[optind], &fe_domid) < 0) { - fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]); - return 1; - } - optind++; - - parse_disk_config_multistring - (&config, argc-optind, (const char* const*)argv + optind, &disk); - - if (dryrun_only) { - char *json = libxl_device_disk_to_json(ctx, &disk); - printf("disk: %s\n", json); - free(json); - if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); } - return 0; - } - - if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) { - fprintf(stderr, "libxl_device_disk_add failed.\n"); - return 1; - } - return 0; -} - -int main_blocklist(int argc, char **argv) -{ - int opt; - int i, nb; - libxl_device_disk *disks; - libxl_diskinfo diskinfo; - - SWITCH_FOREACH_OPT(opt, "", NULL, "block-list", 1) { - /* No options */ - } - - printf("%-5s %-3s %-6s %-5s %-6s %-8s %-30s\n", - "Vdev", "BE", "handle", "state", "evt-ch", "ring-ref", "BE-path"); - for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) { - uint32_t domid; - if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) { - fprintf(stderr, "%s is an invalid domain identifier\n", *argv); - continue; - } - disks = libxl_device_disk_list(ctx, domid, &nb); - if (!disks) { - continue; - } - for (i=0; i<nb; i++) { - if (!libxl_device_disk_getinfo(ctx, domid, &disks[i], &diskinfo)) { - /* Vdev BE hdl st evch rref BE-path*/ - printf("%-5d %-3d %-6d %-5d %-6d %-8d %-30s\n", - diskinfo.devid, diskinfo.backend_id, diskinfo.frontend_id, - diskinfo.state, diskinfo.evtch, diskinfo.rref, diskinfo.backend); - libxl_diskinfo_dispose(&diskinfo); - } - libxl_device_disk_dispose(&disks[i]); - } - free(disks); - } - return 0; -} - -int main_blockdetach(int argc, char **argv) -{ - uint32_t domid; - int opt, rc = 0; - libxl_device_disk disk; - - SWITCH_FOREACH_OPT(opt, "", NULL, "block-detach", 2) { - /* No options */ - } - - domid = xfind_domain(argv[optind]); - - if (libxl_vdev_to_device_disk(ctx, domid, argv[optind+1], &disk)) { - fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); - return 1; - } - rc = libxl_device_disk_remove(ctx, domid, &disk, 0); - if (rc) { - fprintf(stderr, "libxl_device_disk_remove failed.\n"); - return 1; - } - libxl_device_disk_dispose(&disk); - return rc; -} - - static char *uptime_to_string(unsigned long uptime, int short_mode) { int sec, min, hour, day; -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |