]> sourceware.org Git - lvm2.git/commitdiff
o pvcreate
authorJoe Thornber <thornber@redhat.com>
Fri, 12 Oct 2001 10:32:06 +0000 (10:32 +0000)
committerJoe Thornber <thornber@redhat.com>
Fri, 12 Oct 2001 10:32:06 +0000 (10:32 +0000)
o added uuid unit

o stubbed partition stuff

16 files changed:
include/.symlinks
lib/Makefile.in
lib/device/device.c
lib/device/device.h
lib/format1/format1.c
lib/metadata/metadata.c
lib/metadata/metadata.h
lib/mm/pool.c
lib/mm/pool.h
lib/uuid/uuid.c [new file with mode: 0644]
lib/uuid/uuid.h [new file with mode: 0644]
tools/Makefile.in
tools/lvm.c
tools/pvcreate.c
tools/stub.h
tools/tools.h

index 59c61cda21b176bfd47b2a2bf228167c2e7fe5df..8a8e1251b0195e7d4ad7909c0e2a97edda80e666 100644 (file)
@@ -12,3 +12,4 @@
 ../lib/mm/dbg_malloc.h
 ../lib/mm/pool.h
 ../lib/mm/xlate.h
+../lib/uuid/uuid.h
index cb4a085971753bfaac1b475a68db3d4bdc26b76d..0fb07dbff0b4757f4d8394a1a51f0de9a09ee3f5 100644 (file)
@@ -13,6 +13,7 @@ SOURCES=\
        datastruct/hash.c \
        device/dev-cache.c \
        device/dev-io.c \
+       device/device.c \
        filters/filter.c \
        format1/disk-rep.c \
        format1/format1.c \
@@ -20,8 +21,10 @@ SOURCES=\
        format1/layout.c \
        format1/vg_number.c \
        log/log.c \
+       metadata/metadata.c \
        mm/dbg_malloc.c \
-       mm/pool.c
+       mm/pool.c \
+       uuid/uuid.c
 
 TARGETS=liblvm.a
 
index 12c5e2264ffe45b62e4c129ce66c8d9098346871..a410a17c71e7c0bbf21625c53c3f159fac4fdf0a 100644 (file)
@@ -38,6 +38,8 @@
 #include <linux/major.h>
 #include <linux/genhd.h>
 
+
+
 #if 0
 int _get_partition_type(struct dev_filter *filter, struct device *d);
 
index 079c26ba5f760d6de2f08b69587533123b8f44bc..7bf30d073076933a41a3d4df456f510d6cb7c955 100644 (file)
@@ -29,8 +29,10 @@ int64_t dev_read(struct device *dev,
 int64_t dev_write(struct device *dev,
                  uint64_t offset, int64_t len, void *buffer);
 
-/* FIXME: Alasdair lets add more query functions here for accessing
-   the partition information, this can then be used by your filter. */
+
+static inline int is_lvm_partition(const char *name) {
+       return 1;
+}
 
 #define LVM_DEFAULT_DIR_PREFIX "/dev/"
 /* FIXME Allow config file override */
index 858e3c70d020cf0d1338d413e0d3753ee5fb2ade..b72f7d6de325bdf3ea5b65e9268bd34db47d3e83 100644 (file)
@@ -332,7 +332,6 @@ static int _pv_setup(struct io_space *is, struct physical_volume *pv,
        }
 
        pv->exported = NULL;
-
         pv->status = ACTIVE;
 
        if (!dev_get_size(pv->dev, &pv->size)) {
index e0c82a634ba504072e35a861cc8db2382a4fc5f0..5981b305cf8279d35ef129b0653bf9956934be08 100644 (file)
@@ -1,49 +1,51 @@
 /*
- * Copyright (C)  2001 Sistina Software
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
  *
- * This LVM library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This LVM library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this LVM library; if not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA
+ * This file is released under the GPL.
  */
 
-#include <string.h>
-#include "dbg_malloc.h"
-#include "dev-cache.h"
 #include "log.h"
+#include "pool.h"
+#include "device.h"
+#include "dev-cache.h"
 #include "metadata.h"
 
-pv_t *pv_read(struct dev_mgr *dm, const char *pv_name)
-{
-       /* FIXME: Use config to select lvm_v1 format?  Cache results? */
-       /*        Pass structure around rather than pv_name? */
-
-       log_very_verbose("Reading metadata from %s", pv_name);
-
-       return pv_read_lvm_v1(dm, pv_name);
-
-}
+#include <string.h>
 
-pe_disk_t *pv_read_pe(const char *pv_name, const pv_t * pv)
+struct physical_volume *pv_create(const char *name, struct io_space *ios)
 {
-       log_very_verbose("Reading PE metadata from %s", pv_name);
-
-       return pv_read_pe_lvm_v1(pv_name, pv);
+       struct physical_volume *pv = pool_alloc(ios->mem, sizeof(*pv));
+
+       if (!pv) {
+               stack;
+               return NULL;
+       }
+
+        id_create(&pv->id);
+       if (!(pv->dev = dev_cache_get(name, ios->filter))) {
+               log_err("Couldn't find device '%s'", name);
+               goto bad;
+       }
+
+       pv->vg_name = NULL;
+       pv->exported = NULL;
+        pv->status = 0;
+
+       if (!dev_get_size(pv->dev, &pv->size)) {
+               log_err("Couldn't get size of device '%s'", name);
+               goto bad;
+       }
+
+        pv->pe_size = 0;
+        pv->pe_start = 0;
+        pv->pe_count = 0;
+        pv->pe_allocated = 0;
+       return pv;
+
+ bad:
+       pool_free(ios->mem, pv);
+       return NULL;
 }
 
-lv_disk_t *pv_read_lvs(const pv_t *pv)
-{
-       log_very_verbose("Reading LV metadata from %s", pv->pv_name);
 
-       return pv_read_lvs_lvm_v1(pv);
-}
+
index c31c80713890e09d1141879829ff9624a57036d0..9ecf5515a34ba203991ec9a28a1dd1e94eae9600 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001 Sistina Software
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
  *
  * This file is released under the GPL.
  *
@@ -13,8 +13,8 @@
 #include <sys/types.h>
 #include "dev-cache.h"
 #include "list.h"
+#include "uuid.h"
 
-#define ID_LEN 32
 #define NAME_LEN 128
 
 /* Various flags */
 #define IMPORTED_TAG "PV_IMP"  /* Identifier of imported PV */
 
 
-struct id {
-       uint8_t uuid[ID_LEN];
-};
-
 struct physical_volume {
         struct id id;
        struct device *dev;
-       char *vg_name;          /* VG component of name only - not full path */
+       char *vg_name;
        char *exported;
 
         uint32_t status;
@@ -71,7 +67,7 @@ struct pe_specifier {
 struct logical_volume {
         /* disk */
        struct id id;
-        char *name;            /* LV component of name only - not full path */
+        char *name;
 
         uint32_t status;
 
@@ -84,7 +80,7 @@ struct logical_volume {
 
 struct volume_group {
        struct id id;
-       char *name;             /* VG component of name only - not full path */
+       char *name;
 
         uint32_t status;
 
@@ -194,6 +190,15 @@ struct io_space {
        void *private;
 };
 
+/*
+ * Utility functions
+ */
+struct physical_volume *pv_create(const char *name, struct io_space *ios);
+
+
+
+
+
 
 /* FIXME: Move to other files */
 struct io_space *create_text_format(struct dev_filter *filter,
@@ -203,7 +208,6 @@ int id_eq(struct id *op1, struct id *op2);
 
 /* Create consistent new empty structures, populated with defaults */
 struct volume_group *vg_create();
-struct physical_volume *pv_create();
 
 int vg_destroy(struct volume_group *vg);
 
index 11680c57e97d2e5847c54a62d5116a35f070d4ee..34d68cb8f5e56b46de67744f7803a4c0c71ed482 100644 (file)
@@ -91,6 +91,11 @@ void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
        return r;
 }
 
+void pool_empty(struct pool *p)
+{
+       pool_free(p, p->chunk->begin);
+}
+
 void pool_free(struct pool *p, void *ptr)
 {
        struct chunk *c = p->chunk;
index e77c8b5987df2af43f60d8581047f50c476ac1d2..1bfaf8e0cff823fc76acd1bbc6fea234d6321d44 100644 (file)
@@ -18,6 +18,7 @@ void pool_destroy(struct pool *p);
 /* simple allocation/free routines */
 void *pool_alloc(struct pool *p, size_t s);
 void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment);
+void pool_empty(struct pool *p);
 void pool_free(struct pool *p, void *ptr);
 
 /* object building routines */
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c
new file mode 100644 (file)
index 0000000..a96b5ad
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#include "uuid.h"
+#include "log.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static unsigned char _c[] =
+    "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+int id_create(struct id *id)
+{
+       int random, i, len = sizeof(id->uuid);
+
+       memset(id->uuid, 0, len);
+       if ((random = open("/dev/urandom", O_RDONLY)) < 0) {
+               log_sys_error("open", "id_create");
+               return 0;
+       }
+
+       if (read(random, id->uuid, len) != len) {
+               log_sys_error("read", "id_create");
+               return 0;
+       }
+       close(random);
+
+       for (i = 0; i < len; i++)
+               id->uuid[i] = _c[id->uuid[i] % (sizeof(_c) - 1)];
+
+       return 1;
+}
+
+int id_valid(struct id *id)
+{
+       log_err("Joe hasn't written id_valid yet");
+       return 1;
+}
+
+int id_cmp(struct id *lhs, struct id *rhs)
+{
+       return memcmp(lhs->uuid, rhs->uuid, sizeof(lhs->uuid));
+}
diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h
new file mode 100644 (file)
index 0000000..15de1b7
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#ifndef _LVM_UUID_H
+#define _LVM_UUID_H
+
+#include "lvm-types.h"
+
+#define ID_LEN 32
+
+struct id {
+       uint8_t uuid[ID_LEN];
+};
+
+int id_create(struct id *id);
+int id_valid(struct id *id);
+int id_cmp(struct id *lhs, struct id *rhs);
+
+#endif
index 1c75460d6d0fbfefe128a23b2065cef156580657..40a35995939663473139017509e41140f5527609 100644 (file)
@@ -21,13 +21,14 @@ top_srcdir = @top_srcdir@
 VPATH = @srcdir@
 
 SOURCES=\
-       lvm.c\
-       lvmchange.c\
-       toollib.c\
-       vgck.c\
-       vgreduce.c\
-       vgrename.c\
-       vgremove.c\
+       lvm.c \
+       lvmchange.c \
+       pvcreate.c \
+       toollib.c \
+       vgck.c \
+       vgreduce.c \
+       vgrename.c \
+       vgremove.c \
        vgscan.c
 
 TARGETS=\
index 00d6245fdf17caea363ae03061de8c2cd069bc90..e439ce2f19f2a9c6bd92a7ddaf237cd9e4afa8ec 100644 (file)
@@ -1,20 +1,7 @@
 /*
- * Copyright (C) 2001  Sistina Software
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
  *
- * LVM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * LVM 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU CC; see the file COPYING.  If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * This file is released under the GPL.
  */
 
 #include "tools.h"
@@ -25,6 +12,7 @@
 #include <syslog.h>
 #include <libgen.h>
 #include <sys/stat.h>
+#include <ctype.h>
 
 #include "stub.h"
 
@@ -224,7 +212,7 @@ int permission_arg(struct arg *a)
        return 1;
 }
 
-char yes_no_prompt(char *prompt, ...)
+char yes_no_prompt(const char *prompt, ...)
 {
        int c = 0;
        va_list ap;
@@ -237,7 +225,10 @@ char yes_no_prompt(char *prompt, ...)
                }
                c = tolower(getchar());
        }
-       while (getchar() != '\n') ;
+
+       while (getchar() != '\n')
+               ;
+
        return c;
 }
 
index 77ad78b226fcc0c25e0f4b34c2d8757f72e5ae0e..deccb290356aaba0021a510d0b98574aecd9767c 100644 (file)
 /*
- * Copyright (C) 2001 Sistina Software
- *
- * LVM is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * LVM 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with LVM; see the file COPYING.  If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
  *
+ * This file is released under the GPL.
  */
 
 #include "tools.h"
 
-void pvcreate_single(const char *pv_name);
+const char _really_init[] =
+    "Really INITIALIZE physical volume %s of volume group %s [y/n]? ";
 
-int pvcreate(int argc, char **argv)
+/*
+ * See if we may pvcreate on this device.
+ * 0 indicates we may not.
+ */
+static int _check(const char *name)
 {
-       int opt;
-
-       if (!argc) {
-               log_error("Please enter a physical volume path");
-               return EINVALID_CMD_LINE;
-       }
-
-       if (arg_count(yes_ARG) && !arg_count(force_ARG)) {
-               log_error("Option y can only be used with option f");
-               return EINVALID_CMD_LINE;
-       }
+       struct physical_volume *pv;
 
-       for (opt = 0; opt < argc; opt++)
-               pvcreate_single(argv[opt]);
+       /* is the partition type set correctly ? */
+       if ((arg_count(force_ARG) < 1) && !is_lvm_partition(name))
+               return 0;
 
-       return 0;
-}
+       /* is there a pv here already */
+       if (!(pv = ios->pv_read(ios, name)))
+               return 1;
 
-void pvcreate_single(const char *pv_name)
-{
-       int size;
-       struct physical_volume *pv = NULL;
+       /* orphan ? */
+       if (!pv->vg_name[0])
+               return 1;
 
-       struct device *pv_dev;
+       /* never overwrite exported pv's */
+       if (pv->status & EXPORTED_VG) {
+               log_error("Physical volume %s belongs to exported volume"
+                         " group %s", name, pv->vg_name);
+               return 0;
+       }
 
-       if (!(pv_dev = dev_cache_get(pv_name))) {
-               log_error("Device %s not found", pv_name);
-               return;
+       /* we must have -ff to overwrite a non orphan */
+       if (arg_count(force_ARG) < 2) {
+               log_error("Can't initialize physical volume %s of "
+                         "volume group %s without -ff", name, pv->vg_name);
+               return 0;
        }
 
-       if ((size = dev_get_size(pv_dev)) < 0) {
-               log_error("Unable to get size of %s", pv_name);
-               return;
+       /* prompt */
+       if (!arg_count(yes_ARG) &&
+           yes_no_prompt(_really_init, name, pv->vg_name) == 'n') {
+               log_print("physical volume %s not initialized", name);
+               return 0;
        }
 
-       if (arg_count(force_ARG) < 1 && !partition_type_is_lvm(ios, pv_dev)) {
-               return;
+       if (pv->status & ACTIVE) {
+               log_error("Can't create on active physical volume %s", name);
+               return 0;
        }
 
-       pv = ios->pv_read(ios, pv_dev);
+       return 1;
+}
+
+void _single(const char *name)
+{
+       struct physical_volume *pv;
 
-       if (pv && (pv->status & STATUS_EXPORTED)) {
-               log_error("Physical volume %s belongs to exported volume"
-                         " group %s", pv_name, pv->vg_name);
+       if (!_check(name))
                return;
-       }
 
-       if (pv && pv->vg_name[0]) {
-               if (arg_count(force_ARG) < 2) {
-                       log_error("Can't initialize physical volume %s of "
-                                 "volume group %s without -ff", pv_name,
-                                 pv->vg_name);
-                       return;
-               }
-               if (!arg_count(yes_ARG)) {
-                       if (yes_no_prompt
-                           ("Really INITIALIZE physical volume %s"
-                            " of volume group %s [y/n]? ", pv_name,
-                            pv->vg_name) == 'n') {
-                               log_print("Physical volume %s not initialized",
-                                         pv_name);
-                               return;
-                       }
-               }
+       if (arg_count(force_ARG)) {
+               log_print("WARNING: forcing physical volume creation on %s",
+                         name);
 
+               if (pv->vg_name[0])
+                       log_print(" of volume group %s", pv->vg_name);
+               printf("\n");
        }
 
-       if (pv && (pv->status & ACTIVE)) {
-               log_error("Can't create on active physical volume %s", pv_name);
+       if (!(pv = pv_create(name, ios))) {
+               log_err("Failed to setup physical volume %s", name);
                return;
        }
+       log_verbose("set up physical volume for %s with %llu sectors",
+                   name, pv->size);
 
-       if (!pv) {
-               if (!(pv = pv_create()))
-                       return;
-               /* FIXME: Set up initial size & PEs here */
-       }
 
-       if (arg_count(force_ARG)) {
-               /* FIXME: Change to log_print */
-               printf("Warning: Forcing physical volume creation on %s",
-                      pv_name);
-               if (pv->vg_name[0])
-                       printf(" of volume group %s", pv->vg_name);
-               printf("\n");
+       log_verbose("writing physical volume data to disk %s", name);
+       if (!(ios->pv_write(ios, pv))) {
+               log_error("Failed to write physical volume %s", name);
+               return;
        }
 
-       /* FIXME: If PV is in VG, remove it.  NoOp?  Or cache? */
+       log_print("physical volume %s successfully created", name);
+}
 
-       log_verbose("Creating new physical volume");
-       log_verbose("Setting up physical volume for %s with %u sectors",
-                   pv_name, size);
+int pvcreate(int argc, char **argv)
+{
+       int i;
 
-       log_verbose("Writing physical volume data to disk %s", pv_name);
+       if (!argc) {
+               log_error("Please enter a physical volume path");
+               return EINVALID_CMD_LINE;
+       }
 
-       if (!(pv_write(ios, pv))) {
-               log_error("Failed to create physical volume %s", pv_name);
-               return;
+       if (arg_count(yes_ARG) && !arg_count(force_ARG)) {
+               log_error("option y can only be given with option f");
+               return EINVALID_CMD_LINE;
        }
 
-       log_print("Physical volume %s successfully created", pv_name);
+       for (i = 0; i < argc; i++) {
+               _single(argv[i]);
+               pool_empty(ios->mem);
+       }
 
-/* FIXME: Add the dbg_frees throughout! */
-       return;
+       return 0;
 }
index 933281221f00aae6c71de7e8021b50f031321783..906fdf0689af959be6b71d813f28e5d73ac666a8 100644 (file)
@@ -30,7 +30,6 @@ int lvreduce(int argc, char **argv) {return 1;}
 int lvremove(int argc, char **argv) {return 1;}
 int lvrename(int argc, char **argv) {return 1;}
 int lvscan(int argc, char **argv) {return 1;}
-int pvcreate(int argc, char **argv) {return 1;}
 int pvchange(int argc, char **argv) {return 1;}
 int pvdisplay(int argc, char **argv) {return 1;}
 int pvdata(int argc, char **argv) {return 1;}
index 684b57e1b67889407be1e657578cb40fe5a68459..971bb34b447412a0546ac66cc11482b8abeae00d 100644 (file)
@@ -79,7 +79,7 @@ int int_arg(struct arg *a);
 int string_arg(struct arg *a);
 int permission_arg(struct arg *a);
 
-char yes_no_prompt(char *prompt, ...);
+char yes_no_prompt(const char *prompt, ...);
 
 /* we use the enums to access the switches */
 static inline int arg_count(int a) {
This page took 0.05664 seconds and 5 git commands to generate.