Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/iscsi Break out the files relating to storage extents, ...



details:   https://anonhg.NetBSD.org/src/rev/fcb3a827abbb
branches:  trunk
changeset: 588152:fcb3a827abbb
user:      agc <agc%NetBSD.org@localhost>
date:      Thu Feb 09 23:08:31 2006 +0000

description:
Break out the files relating to storage extents, devices and targets into
a separate source file.

diffstat:

 dist/iscsi/include/storage.h  |    5 +-
 dist/iscsi/src/Makefile.in    |    2 +-
 dist/iscsi/src/iscsi-target.c |  323 +-----------------------------------
 dist/iscsi/src/osd-target.c   |    3 +
 dist/iscsi/src/storage.c      |  378 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 388 insertions(+), 323 deletions(-)

diffs (truncated from 772 to 300 lines):

diff -r 4ce242d1fcdf -r fcb3a827abbb dist/iscsi/include/storage.h
--- a/dist/iscsi/include/storage.h      Thu Feb 09 22:28:06 2006 +0000
+++ b/dist/iscsi/include/storage.h      Thu Feb 09 23:08:31 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: storage.h,v 1.1.1.1 2006/02/08 18:56:15 agc Exp $ */
+/* $NetBSD: storage.h,v 1.2 2006/02/09 23:08:31 agc Exp $ */
 
 /*
  * Copyright © 2006 Alistair Crooks.  All rights reserved.
@@ -83,4 +83,7 @@
 
 DEFINE_ARRAY(targv_t, disc_target_t);
 
+int read_conf_file(const char *, targv_t *, devv_t *, extv_t *);
+void write_pid_file(const char *);
+
 #endif /* !STORAGE_H_ */
diff -r 4ce242d1fcdf -r fcb3a827abbb dist/iscsi/src/Makefile.in
--- a/dist/iscsi/src/Makefile.in        Thu Feb 09 22:28:06 2006 +0000
+++ b/dist/iscsi/src/Makefile.in        Thu Feb 09 23:08:31 2006 +0000
@@ -45,7 +45,7 @@
 #
 COMPATOBJS= strlcpy.o snprintf.o strtoll.o
 
-USER_TARGET_OBJS = target.o iscsi.o util.o parameters.o conffile.o ${COMPATOBJS}
+USER_TARGET_OBJS = target.o iscsi.o util.o parameters.o conffile.o storage.o ${COMPATOBJS}
 $(BIN)/osd: osd-target.c osd.c $(USER_TARGET_OBJS)
        $(CC) $(CFLAGS) osd-target.c osd.c $(USER_TARGET_OBJS)  ${PTHREAD_LDFLAGS} ${PTHREAD_LIBS} -o $(BIN)/osd
 $(BIN)/iscsi-target: iscsi-target.c disk.c $(USER_TARGET_OBJS)
diff -r 4ce242d1fcdf -r fcb3a827abbb dist/iscsi/src/iscsi-target.c
--- a/dist/iscsi/src/iscsi-target.c     Thu Feb 09 22:28:06 2006 +0000
+++ b/dist/iscsi/src/iscsi-target.c     Thu Feb 09 23:08:31 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: iscsi-target.c,v 1.2 2006/02/09 15:11:40 he Exp $ */
+/* $NetBSD: iscsi-target.c,v 1.3 2006/02/09 23:08:31 agc Exp $ */
 
 /*
  * Copyright © 2006 Alistair Crooks.  All rights reserved.
@@ -57,329 +57,10 @@
 #include "conffile.h"
 #include "storage.h"
 
-/* let's use symbolic names for the fields in the config file */
-enum {
-       EXTENT_NAME_COL = 0,
-       EXTENT_DEVICE_COL = 1,
-       EXTENT_SACRED_COL = 2,
-       EXTENT_LENGTH_COL = 3,
-
-       DEVICE_NAME_COL = 0,
-       DEVICE_RAIDLEVEL_COL = 1,
-       DEVICE_LENGTH_COL = 2,
-
-       TARGET_NAME_COL = 0,
-       TARGET_DEVICE_COL = 1,
-       TARGET_NETMASK_COL = 2
-};
-
-
 static int      g_main_pid;
 
 static globals_t       g;
 
-/* find an extent by name */
-static disc_extent_t *
-find_extent(extv_t *evp, char *s)
-{
-       int     i;
-
-       for (i = 0 ; i < evp->c ; i++) {
-               if (strcmp(evp->v[i].extent, s) == 0) {
-                       return &evp->v[i];
-               }
-       }
-       return NULL;
-}
-
-/* allocate space for a new extent */
-static int
-do_extent(conffile_t *cf, extv_t *evp, ent_t *ep)
-{
-       char    *cp;
-
-       if (find_extent(evp, ep->sv.v[EXTENT_NAME_COL]) != NULL) {
-               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-               (void) fprintf(stderr, "Error: attempt to re-define extent `%s'\n", ep->sv.v[EXTENT_NAME_COL]);
-               return 0;
-       }
-       ALLOC(disc_extent_t, evp->v, evp->size, evp->c, 14, 14, "do_extent", exit(EXIT_FAILURE));
-       evp->v[evp->c].extent = strdup(ep->sv.v[EXTENT_NAME_COL]);
-       evp->v[evp->c].dev = strdup(ep->sv.v[EXTENT_DEVICE_COL]);
-       evp->v[evp->c].sacred = strtoll(ep->sv.v[EXTENT_SACRED_COL], NULL, 10);
-       evp->v[evp->c].len = strtoll(ep->sv.v[EXTENT_LENGTH_COL], &cp, 10);
-       if (cp != NULL) {
-               switch(tolower((unsigned)*cp)) {
-               case 't':
-                       evp->v[evp->c].len *= (uint64_t)(1024ULL * 1024ULL * 1024ULL * 1024ULL);
-                       break;
-               case 'g':
-                       evp->v[evp->c].len *= (uint64_t)(1024ULL * 1024ULL * 1024ULL);
-                       break;
-               case 'm':
-                       evp->v[evp->c].len *= (uint64_t)(1024ULL * 1024ULL);
-                       break;
-               case 'k':
-                       evp->v[evp->c].len *= (uint64_t)1024ULL;
-                       break;
-               }
-       }
-       evp->c += 1;
-       return 1;
-}
-
-/* find a device by name */
-static disc_device_t *
-find_device(devv_t *devvp, char *s)
-{
-       int     i;
-
-       for (i = 0 ; i < devvp->c ; i++) {
-               if (strcmp(devvp->v[i].dev, s) == 0) {
-                       return &devvp->v[i];
-               }
-       }
-       return NULL;
-}
-
-/* return the size of the sub-device/extent */
-static uint64_t
-getsize(conffile_t *cf, devv_t *devvp, extv_t *evp, char *s)
-{
-       disc_extent_t   *xp;
-       disc_device_t   *dp;
-
-       if ((xp = find_extent(evp, s)) != NULL) {
-               return xp->len;
-       }
-       if ((dp = find_device(devvp, s)) != NULL) {
-               switch (dp->xv[0].type) {
-               case DE_EXTENT:
-                       return dp->xv[0].u.xp->len;
-               case DE_DEVICE:
-                       return dp->xv[0].u.dp->len;
-               }
-       }
-       (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-       (void) fprintf(stderr, "Warning: sub-device/extent `%s' not found\n", s);
-       return 0;
-}
-
-/* allocate space for a device */
-static int
-do_device(conffile_t *cf, devv_t *devvp, extv_t *evp, ent_t *ep)
-{
-       if (find_device(devvp, ep->sv.v[DEVICE_NAME_COL]) != NULL) {
-               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-               (void) fprintf(stderr, "Error: attempt to re-define device `%s'\n", ep->sv.v[DEVICE_NAME_COL]);
-               return 0;
-       }
-       ALLOC(disc_device_t, devvp->v, devvp->size, devvp->c, 14, 14, "do_device", exit(EXIT_FAILURE));
-       devvp->v[devvp->c].dev = strdup(ep->sv.v[DEVICE_NAME_COL]);
-       devvp->v[devvp->c].raid = (strncasecmp(ep->sv.v[DEVICE_RAIDLEVEL_COL], "raid", 4) == 0) ? atoi(&ep->sv.v[DEVICE_RAIDLEVEL_COL][4]) : 0;
-       devvp->v[devvp->c].size = ep->sv.c - 2;
-       devvp->v[devvp->c].len = getsize(cf, devvp, evp, ep->sv.v[DEVICE_LENGTH_COL]);
-       NEWARRAY(disc_de_t, devvp->v[devvp->c].xv, ep->sv.c - 2, "do_device", exit(EXIT_FAILURE));
-       for (devvp->v[devvp->c].c = 0 ; devvp->v[devvp->c].c < devvp->v[devvp->c].size ; devvp->v[devvp->c].c++) {
-               if ((devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp = find_extent(evp, ep->sv.v[devvp->v[devvp->c].c + 2])) != NULL) {
-                       if (devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp->used) {
-                               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-                               (void) fprintf(stderr, "Error: extent `%s' has already been used\n", ep->sv.v[devvp->v[devvp->c].c + 2]);
-                               return 0;
-                       }
-                       if (devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp->len != devvp->v[devvp->c].len) {
-                               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-                               (void) fprintf(stderr, "Error: extent `%s' has size %" PRIu64 ", not %" PRIu64"\n", ep->sv.v[devvp->v[devvp->c].c + 2], 
devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp->len, devvp->v[devvp->c].len);
-                               return 0;
-                       }
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].type = DE_EXTENT;
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].size = devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp->len;
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.xp->used = 1;
-               } else if ((devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.dp = find_device(devvp, ep->sv.v[devvp->v[devvp->c].c + 2])) != NULL) {
-                       if (devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.dp->used) {
-                               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-                               (void) fprintf(stderr, "Error: device `%s' has already been used\n", ep->sv.v[devvp->v[devvp->c].c + 2]);
-                               return 0;
-                       }
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].type = DE_DEVICE;
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.dp->used = 1;
-                       devvp->v[devvp->c].xv[devvp->v[devvp->c].c].size = devvp->v[devvp->c].xv[devvp->v[devvp->c].c].u.dp->len;
-               } else {
-                       (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-                       (void) fprintf(stderr, "Error: no extent or device found for `%s'\n", ep->sv.v[devvp->v[devvp->c].c + 2]);
-                       return 0;
-               }
-       }
-       if (devvp->v[devvp->c].raid == 1) {
-               /* check we have more than 1 device/extent */
-               if (devvp->v[devvp->c].c < 2) {
-                       (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-                       (void) fprintf(stderr, "Error: device `%s' is specified as RAID1, but has only %d sub-devices/extents\n", devvp->v[devvp->c].dev, devvp->v[devvp->c].c);
-                       return 0;
-               }
-       }
-       devvp->c += 1;
-       return 1;
-}
-
-/* find a target by name */
-static disc_target_t *
-find_target(targv_t *tvp, char *s)
-{
-       int     i;
-
-       for (i = 0 ; i < tvp->c ; i++) {
-               if (strcmp(tvp->v[i].target, s) == 0) {
-                       return &tvp->v[i];
-               }
-       }
-       return NULL;
-}
-
-/* allocate space for a new target */
-static int
-do_target(conffile_t *cf, targv_t *tvp, devv_t *devvp, extv_t *evp, ent_t *ep)
-{
-       disc_extent_t   *xp;
-       disc_device_t   *dp;
-
-       if (find_target(tvp, ep->sv.v[TARGET_NAME_COL]) != NULL) {
-               (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-               (void) fprintf(stderr, "Error: attempt to re-define target `%s'\n", ep->sv.v[TARGET_NAME_COL]);
-               return 0;
-       }
-       ALLOC(disc_target_t, tvp->v, tvp->size, tvp->c, 14, 14, "do_target", exit(EXIT_FAILURE));
-       if ((dp = find_device(devvp, ep->sv.v[TARGET_DEVICE_COL])) != NULL) {
-               tvp->v[tvp->c].de.type = DE_DEVICE;
-               tvp->v[tvp->c].de.u.dp = dp;
-               tvp->v[tvp->c].target = strdup(ep->sv.v[TARGET_NAME_COL]);
-               tvp->v[tvp->c].mask = strdup(ep->sv.v[TARGET_NETMASK_COL]);
-               tvp->c += 1;
-               return 1;
-       }
-       if ((xp = find_extent(evp, ep->sv.v[TARGET_DEVICE_COL])) != NULL) {
-               tvp->v[tvp->c].de.type = DE_EXTENT;
-               tvp->v[tvp->c].de.u.xp = xp;
-               tvp->v[tvp->c].target = strdup(ep->sv.v[TARGET_NAME_COL]);
-               tvp->v[tvp->c].mask = strdup(ep->sv.v[TARGET_NETMASK_COL]);
-               tvp->c += 1;
-               return 1;
-       }
-       (void) fprintf(stderr, "%s:%d: ", conffile_get_name(cf), conffile_get_lineno(cf));
-       (void) fprintf(stderr, "Error: no device or extent found for `%s'\n", ep->sv.v[TARGET_DEVICE_COL]);
-       return 0;
-}
-
-/* print an extent */
-static void
-pextent(disc_extent_t *ep, int indent)
-{
-       int     i;
-
-       for (i = 0 ; i < indent ; i++) {
-               (void) fputc('\t', stdout);
-       }
-       printf("%s:%s:%" PRIu64 ":%" PRIu64 "\n", ep->extent, ep->dev, ep->sacred, ep->len);
-}
-
-static void pdevice(disc_device_t *, int);
-
-/* print information about an extent or a device */
-static void
-pu(disc_de_t *dep, int indent)
-{
-       switch(dep->type) {
-       case DE_EXTENT:
-               pextent(dep->u.xp, indent);
-               break;
-       case DE_DEVICE:
-               pdevice(dep->u.dp, indent);
-               break;
-       }
-}
-
-/* print information about a device */
-static void
-pdevice(disc_device_t *dp, int indent)
-{
-       int     i;
-       int     j;
-
-       for (i = 0 ; i < indent ; i++) {
-               (void) fputc('\t', stdout);
-       }
-       printf("%s:RAID%d\n", dp->dev, dp->raid);
-       for (j = 0 ; j < dp->c ; j++) {
-               pu(&dp->xv[j], indent + 1);
-       }
-}
-
-/* print informnation about a target */



Home | Main Index | Thread Index | Old Index