Date: Thu, 12 Jul 2012 16:53:38 +0000 From: vchan@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239309 - soc2012/vchan/gtcp/bwalex-tc-play Message-ID: <20120712165338.ED2D41065674@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: vchan Date: Thu Jul 12 16:53:38 2012 New Revision: 239309 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239309 Log: whole lotta changes to tcplay Modified: soc2012/vchan/gtcp/bwalex-tc-play/Makefile soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c Modified: soc2012/vchan/gtcp/bwalex-tc-play/Makefile ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/Makefile Thu Jul 12 16:49:50 2012 (r239308) +++ soc2012/vchan/gtcp/bwalex-tc-play/Makefile Thu Jul 12 16:53:38 2012 (r239309) @@ -21,7 +21,7 @@ OBJS= tcplay.o crc32.o safe_mem.o io.o hdr.o humanize.o OBJS+= crypto.o generic_xts.o -CFLAGS+= $(WARNFLAGS) -I/usr/include +CFLAGS+= $(WARNFLAGS) -I/usr/include -I/usr/local/include ifeq (${DEBUG}, yes) CFLAGS+= -O0 -g -DDEBUG Modified: soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c Thu Jul 12 16:49:50 2012 (r239308) +++ soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c Thu Jul 12 16:53:38 2012 (r239309) @@ -31,6 +31,7 @@ //#if defined(__DragonFly__) #include <sys/param.h> + //#endif #include <stdio.h> @@ -42,12 +43,24 @@ #include <string.h> #include <err.h> #include <time.h> + //#if defined(__linux__) //#include <libdevmapper.h> //#include <uuid/uuid.h> //#elif defined(__DragonFly__) //#include <libdm.h> #include <uuid.h> + +//FreeBSD specific headers +#include <stdint.h> +#include <fcntl.h> +#include <assert.h> +#include <sys/time.h> +#include <sys/bio.h> +#include <sys/disk.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/syslog.h> #include <geom/gate/g_gate.h> #include <ggate.h> @@ -71,6 +84,7 @@ /* new for FreeBSD */ static int unit = G_GATE_UNIT_AUTO; static int force = 0; +static unsigned sectorsize = 0; void tc_log(int is_err, const char *fmt, ...) @@ -926,41 +940,98 @@ return -1; } +/* not correct yet int -map_volume(const char *map_name, int sflag, - int interactive, time_t timeout) - +map_volume(int fd, int interactive) { - struct g_gate_ctl_create ggioc; - int fd; + struct g_gate_ctl_io ggio; + size_t bsize; + + if (g_gate_verbose == 0) { + if (daemon(0, 0) == -1) { + g_gate_destroy(unit, 1); + err(EXIT_FAILURE, "Cannot daemonize"); + } + } + g_gate_log(LOG_DEBUG, "Worker created: %u.", getpid()); + ggio.gctl_version = G_GATE_VERSION; + ggio.gctl_unit = unit; + bsize = sectorsize; + ggio.gctl_data = malloc(bsize); + for (;;) { + int error; +once_again: + ggio.gctl_length = bsize; + ggio.gctl_error = 0; + g_gate_ioctl(G_GATE_CMD_START, &ggio); + error = ggio.gctl_error; + switch (error) { + case 0: + break; + case ECANCELED: + /* Exit gracefully. + free(ggio.gctl_data); + g_gate_close_device(); + close(fd); + exit(EXIT_SUCCESS); + case ENOMEM: + /* Buffer too small. + assert(ggio.gctl_cmd == BIO_DELETE || + ggio.gctl_cmd == BIO_WRITE); + ggio.gctl_data = realloc(ggio.gctl_data, + ggio.gctl_length); + if (ggio.gctl_data != NULL) { + bsize = ggio.gctl_length; + goto once_again; + } + /* FALLTHROUGH + case ENXIO: + default: + g_gate_xlog("ioctl(/dev/%s): %s.", G_GATE_CTL_NAME, + strerror(error)); + } + + error = 0; + switch (ggio.gctl_cmd) { + case BIO_READ: + if ((size_t)ggio.gctl_length > bsize) { + ggio.gctl_data = realloc(ggio.gctl_data, + ggio.gctl_length); + if (ggio.gctl_data != NULL) + bsize = ggio.gctl_length; + else + error = ENOMEM; + } + if (error == 0) { + if (pread(fd, ggio.gctl_data, ggio.gctl_length, + ggio.gctl_offset) == -1) { + error = errno; + } + } + break; + case BIO_DELETE: + case BIO_WRITE: + if (pwrite(fd, ggio.gctl_data, ggio.gctl_length, + ggio.gctl_offset) == -1) { + error = errno; + } + break; + default: + error = EOPNOTSUPP; + } + + ggio.gctl_error = error; + g_gate_ioctl(G_GATE_CMD_DONE, &ggio); + } - fd = open(map_name, g_gate_openflags(sflags) | O_DIRECT | O_FSYNC); - if (fd == -1) - err(EXIT_FAILURE, "Cannot open %s", map_name); - ggioc.gctl_version = G_GATE_VERSION; - ggioc.gctl_unit = unit; - ggioc.gctl_mediasize = g_gate_mediasize(fd); - if (sectorsize == 0) - sectorsize = g_gate_sectorsize(fd); - ggioc.gctl_sectorsize = sectorsize; - ggioc.gctl_timeout = timeout; - ggioc.gctl_flags = sflags; - ggioc.gctl_maxcount = 0; - strlcpy(ggioc.gctl_info, map_name, sizeof(ggioc.gctl_info)); - g_gate_ioctl(G_GATE_CMD_CREATE, &ggioc); - if (unit == -1) - printf("%s%u\n", G_GATE_PROVIDER_NAME, ggioc.gctl_unit); - unit = ggioc.gctl_unit; - g_gatel_serve(fd); -} if (interactive) printf("All ok!\n"); return 0; -} -/* +}*/ + int map_volume(const char *map_name, const char *device, int sflag, const char *sys_dev, int protect_hidden, const char *keyfiles[], @@ -971,6 +1042,7 @@ { struct tcplay_info *info; int error; + int fd; info = info_map_common(device, sflag, sys_dev, protect_hidden, keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, @@ -979,7 +1051,7 @@ if (info == NULL) return -1; - if ((error = dm_setup(map_name, info)) != 0) { + if ((error = dm_setup(fd, info)) != 0) { tc_log(1, "Could not set up mapping %s\n", map_name); if (info->hdr) free_safe_mem(info->hdr); @@ -994,7 +1066,7 @@ return 0; } -*/ + static int @@ -1038,7 +1110,7 @@ } int -dm_setup(const char *mapname, struct tcplay_info *info) +dm_setup(int fd, struct tcplay_info *info) { /* Commented out variables not needed in freeBSD*/ struct tc_cipher_chain *cipher_chain; @@ -1080,7 +1152,7 @@ cipher_chain = cipher_chain->prev, j++) { cookie = 0; - force = 1; //used in g_gate_destroy + //force = 1; used in g_gate_destroy /* aes-cbc-essiv:sha256 7997f8af... 0 /dev/ad0s0a 8 */ /* iv off---^ block off--^ */ @@ -1101,18 +1173,18 @@ /* * If this is the last element in the cipher chain, use the * final map name. Otherwise pick a secondary name... - */ + if (cipher_chain->prev == NULL) strcpy(map, mapname); else sprintf(map, "%s.%d", mapname, j); - /* changed from, "if ((dm_task_set_name(dmt, map)) == 0" */ + /* changed from, "if ((dm_task_set_name(dmt, map)) == 0" if (map == NULL) { tc_log(1, "task_set_name failed\n"); ret = -1; goto out; - } + }*/ /*#if defined(__linux__) uuid_generate(info->uuid); @@ -1175,8 +1247,89 @@ dm_udev_wait(cookie); */ +//FreeBSD + + struct g_gate_ctl_io ggio; + size_t bsize; - if ((r = asprintf(&uu_stack[uu_stack_idx++], "%s", map)) < 0) + if (g_gate_verbose == 0) { + if (daemon(0, 0) == -1) { + g_gate_destroy(unit, 1); + err(EXIT_FAILURE, "Cannot daemonize"); + } + } + g_gate_log(LOG_DEBUG, "Worker created: %u.", getpid()); + ggio.gctl_version = G_GATE_VERSION; + ggio.gctl_unit = unit; + bsize = sectorsize; + ggio.gctl_data = malloc(bsize); + for (;;) { + int error; +once_again: + ggio.gctl_length = bsize; + ggio.gctl_error = 0; + g_gate_ioctl(G_GATE_CMD_START, &ggio); + error = ggio.gctl_error; + switch (error) { + case 0: + break; + case ECANCELED: + /* Exit gracefully. */ + free(ggio.gctl_data); + g_gate_close_device(); + close(fd); + exit(EXIT_SUCCESS); + case ENOMEM: + /* Buffer too small. */ + assert(ggio.gctl_cmd == BIO_DELETE || + ggio.gctl_cmd == BIO_WRITE); + ggio.gctl_data = realloc(ggio.gctl_data, + ggio.gctl_length); + if (ggio.gctl_data != NULL) { + bsize = ggio.gctl_length; + goto once_again; + } + /* FALLTHROUGH */ + case ENXIO: + default: + g_gate_xlog("ioctl(/dev/%s): %s.", G_GATE_CTL_NAME, + strerror(error)); + } + + error = 0; + switch (ggio.gctl_cmd) { + case BIO_READ: + if ((size_t)ggio.gctl_length > bsize) { + ggio.gctl_data = realloc(ggio.gctl_data, + ggio.gctl_length); + if (ggio.gctl_data != NULL) + bsize = ggio.gctl_length; + else + error = ENOMEM; + } + if (error == 0) { + if (pread(fd, ggio.gctl_data, ggio.gctl_length, + ggio.gctl_offset) == -1) { + error = errno; + } + } + break; + case BIO_DELETE: + case BIO_WRITE: + if (pwrite(fd, ggio.gctl_data, ggio.gctl_length, + ggio.gctl_offset) == -1) { + error = errno; + } + break; + default: + error = EOPNOTSUPP; + } + + ggio.gctl_error = error; + g_gate_ioctl(G_GATE_CMD_DONE, &ggio); + } + +/* if ((r = asprintf(&uu_stack[uu_stack_idx++], "%s", map)) < 0) tc_log(1, "warning, asprintf failed. won't be able to " "unroll changes\n"); @@ -1185,15 +1338,15 @@ start = 0; sprintf(dev, "/dev/mapper/%s.%d", mapname, j); - g_gate_destroy(unit, force); /* was dm_task_destroy(dmt); */ - /*not needed in FreeBSD dm_task_update_nodes(); */ + /* was dm_task_destroy(dmt); + /*not needed in FreeBSD dm_task_update_nodes(); } out: /* * If an error occured, try to unroll changes made before it * happened. - */ + if (ret) { j = uu_stack_idx; while (j > 0) { @@ -1209,7 +1362,7 @@ } } } - +*/ while (uu_stack_idx > 0) free(uu_stack[--uu_stack_idx]);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120712165338.ED2D41065674>