diff options
author | lulf <lulf@FreeBSD.org> | 2009-04-10 08:50:14 +0000 |
---|---|---|
committer | lulf <lulf@FreeBSD.org> | 2009-04-10 08:50:14 +0000 |
commit | 62687638dfa1347290a308e562153a2314cbd8fa (patch) | |
tree | dbef804cce038f6daa1d9598a974dc10f18afecf /sys/geom/vinum | |
parent | fbd36468425151a258c7a90df46c0de1a069a137 (diff) | |
download | FreeBSD-src-62687638dfa1347290a308e562153a2314cbd8fa.zip FreeBSD-src-62687638dfa1347290a308e562153a2314cbd8fa.tar.gz |
- Move out allocation part of different gvinum objects into its own routine and
make use of it in the gvinum userland code.
Diffstat (limited to 'sys/geom/vinum')
-rw-r--r-- | sys/geom/vinum/geom_vinum_share.c | 100 | ||||
-rw-r--r-- | sys/geom/vinum/geom_vinum_share.h | 4 |
2 files changed, 76 insertions, 28 deletions
diff --git a/sys/geom/vinum/geom_vinum_share.c b/sys/geom/vinum/geom_vinum_share.c index c3ddd4c..eb70c28 100644 --- a/sys/geom/vinum/geom_vinum_share.c +++ b/sys/geom/vinum/geom_vinum_share.c @@ -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")) { diff --git a/sys/geom/vinum/geom_vinum_share.h b/sys/geom/vinum/geom_vinum_share.h index 9a93968..5646d6b 100644 --- a/sys/geom/vinum/geom_vinum_share.h +++ b/sys/geom/vinum/geom_vinum_share.h @@ -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 **); |