Author: lulf
Date: Fri Apr 10 08:50:14 2009
New Revision: 190881
URL: http://svn.freebsd.org/changeset/base/190881

Log:
  - Move out allocation part of different gvinum objects into its own routine 
and
    make use of it in the gvinum userland code.

Modified:
  head/sbin/gvinum/gvinum.c
  head/sys/geom/vinum/geom_vinum_share.c
  head/sys/geom/vinum/geom_vinum_share.h

Modified: head/sbin/gvinum/gvinum.c
==============================================================================
--- head/sbin/gvinum/gvinum.c   Fri Apr 10 06:16:14 2009        (r190880)
+++ head/sbin/gvinum/gvinum.c   Fri Apr 10 08:50:14 2009        (r190881)
@@ -433,10 +433,9 @@ create_drive(char *device)
        req = gctl_get_handle();
        gctl_ro_param(req, "class", -1, "VINUM");
        gctl_ro_param(req, "verb", -1, "create");
-       d = malloc(sizeof(struct gv_drive));
+       d = gv_alloc_drive();
        if (d == NULL)
                err(1, "unable to allocate for gv_drive object");
-       memset(d, 0, sizeof(struct gv_drive));
 
        strlcpy(d->name, drivename, sizeof(d->name));
        strlcpy(d->device, device, sizeof(d->device));

Modified: head/sys/geom/vinum/geom_vinum_share.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum_share.c      Fri Apr 10 06:16:14 2009        
(r190880)
+++ head/sys/geom/vinum/geom_vinum_share.c      Fri Apr 10 08:50:14 2009        
(r190881)
@@ -367,16 +367,29 @@ gv_plexorg_short(int org)
        }
 }
 
-/* Get a new drive object. */
-struct gv_drive *
-gv_new_drive(int max, char *token[])
+struct gv_sd *
+gv_alloc_sd(void)
 {
-       struct gv_drive *d;
-       int j, errors;
-       char *ptr;
+       struct gv_sd *s;
 
-       if (token[1] == NULL || *token[1] == '\0')
+#ifdef _KERNEL
+       s = g_malloc(sizeof(struct gv_sd), M_NOWAIT);
+#else
+       s = malloc(sizeof(struct gv_sd));
+#endif
+       if (s == NULL)
                return (NULL);
+       bzero(s, sizeof(struct gv_sd));
+       s->plex_offset = -1;
+       s->size = -1;
+       s->drive_offset = -1;
+       return (s);
+}
+
+struct gv_drive *
+gv_alloc_drive(void)
+{
+       struct gv_drive *d;
 
 #ifdef _KERNEL
        d = g_malloc(sizeof(struct gv_drive), M_NOWAIT);
@@ -386,7 +399,54 @@ gv_new_drive(int max, char *token[])
        if (d == NULL)
                return (NULL);
        bzero(d, sizeof(struct gv_drive));
+       return (d);
+}
+
+struct gv_volume *
+gv_alloc_volume(void)
+{
+       struct gv_volume *v;
+
+#ifdef _KERNEL
+       v = g_malloc(sizeof(struct gv_volume), M_NOWAIT);
+#else
+       v = malloc(sizeof(struct gv_volume));
+#endif
+       if (v == NULL)
+               return (NULL);
+       bzero(v, sizeof(struct gv_volume));
+       return (v);
+}
+
+struct gv_plex *
+gv_alloc_plex(void)
+{
+       struct gv_plex *p;
 
+#ifdef _KERNEL
+       p = g_malloc(sizeof(struct gv_plex), M_NOWAIT);
+#else
+       p = malloc(sizeof(struct gv_plex));
+#endif
+       if (p == NULL)
+               return (NULL);
+       bzero(p, sizeof(struct gv_plex));
+       return (p);
+}
+
+/* Get a new drive object. */
+struct gv_drive *
+gv_new_drive(int max, char *token[])
+{
+       struct gv_drive *d;
+       int j, errors;
+       char *ptr;
+
+       if (token[1] == NULL || *token[1] == '\0')
+               return (NULL);
+       d = gv_alloc_drive();
+       if (d == NULL)
+               return (NULL);
        errors = 0;
        for (j = 1; j < max; j++) {
                if (!strcmp(token[j], "state")) {
@@ -434,14 +494,9 @@ gv_new_volume(int max, char *token[])
        if (token[1] == NULL || *token[1] == '\0')
                return (NULL);
 
-#ifdef _KERNEL
-       v = g_malloc(sizeof(struct gv_volume), M_NOWAIT);
-#else
-       v = malloc(sizeof(struct gv_volume));
-#endif
+       v = gv_alloc_volume();
        if (v == NULL)
                return (NULL);
-       bzero(v, sizeof(struct gv_volume));
 
        errors = 0;
        for (j = 1; j < max; j++) {
@@ -479,14 +534,9 @@ gv_new_plex(int max, char *token[])
        if (token[1] == NULL || *token[1] == '\0')
                return (NULL);
 
-#ifdef _KERNEL
-       p = g_malloc(sizeof(struct gv_plex), M_NOWAIT);
-#else
-       p = malloc(sizeof(struct gv_plex));
-#endif
+       p = gv_alloc_plex();
        if (p == NULL)
                return (NULL);
-       bzero(p, sizeof(struct gv_plex));
 
        errors = 0;
        for (j = 1; j < max; j++) {
@@ -546,6 +596,8 @@ gv_new_plex(int max, char *token[])
        return (p);
 }
 
+
+
 /* Get a new subdisk object. */
 struct gv_sd *
 gv_new_sd(int max, char *token[])
@@ -556,18 +608,10 @@ gv_new_sd(int max, char *token[])
        if (token[1] == NULL || *token[1] == '\0')
                return (NULL);
 
-#ifdef _KERNEL
-       s = g_malloc(sizeof(struct gv_sd), M_NOWAIT);
-#else
-       s = malloc(sizeof(struct gv_sd));
-#endif
+       s = gv_alloc_sd();
        if (s == NULL)
                return (NULL);
-       bzero(s, sizeof(struct gv_sd));
 
-       s->plex_offset = -1;
-       s->size = -1;
-       s->drive_offset = -1;
        errors = 0;
        for (j = 1; j < max; j++) {
                if (!strcmp(token[j], "name")) {

Modified: head/sys/geom/vinum/geom_vinum_share.h
==============================================================================
--- head/sys/geom/vinum/geom_vinum_share.h      Fri Apr 10 06:16:14 2009        
(r190880)
+++ head/sys/geom/vinum/geom_vinum_share.h      Fri Apr 10 08:50:14 2009        
(r190881)
@@ -41,6 +41,10 @@ enum {
 off_t  gv_sizespec(char *);
 int    gv_tokenize(char *, char **, int);
 
+struct gv_sd    *gv_alloc_sd(void);
+struct gv_volume *gv_alloc_volume(void);
+struct gv_plex  *gv_alloc_plex(void);
+struct gv_drive         *gv_alloc_drive(void);
 struct gv_drive         *gv_new_drive(int, char **);
 struct gv_plex  *gv_new_plex(int, char **);
 struct gv_sd    *gv_new_sd(int, char **);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to