]> sourceware.org Git - lvm2.git/commitdiff
Update pvck to read labels on disk, with flexible --labelsector
authorDave Wysochanski <dwysocha@redhat.com>
Wed, 25 Apr 2007 20:03:16 +0000 (20:03 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Wed, 25 Apr 2007 20:03:16 +0000 (20:03 +0000)
parameter.

--

WHATS_NEW
lib/metadata/metadata.c
lib/metadata/metadata.h
man/pvck.8
tools/commands.h
tools/pvck.c

index bb6b70867f9e89f17261949bf3e49c59b8d78fdb..0f3e9f1d58748d4478f1b1a561807e3f62778f40 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.25 -
 =================================
+  Update pvck to read labels on disk, with --labelsector parameter
   Add count_chars and count_chars_len functions
   Add /sys/block listings to lvm_dump.sh
   Make lvm_dump.sh list /dev recursively
index bfa74d8db6f7f8ccdd839fb87475a6788aaf0dbf..70b6c1b082e5d1419492c505657f04482ba21aac 100644 (file)
@@ -1555,3 +1555,35 @@ int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv)
 
        return 1;
 }
+/*
+ * Returns:
+ *  0 - fail
+ *  1 - success
+ */
+int pv_analyze(struct cmd_context *cmd, const char *pv_name,
+              int64_t label_sector)
+{
+       struct label *label;
+       struct device *dev;
+
+       dev = dev_cache_get(pv_name, cmd->filter);
+       if (!dev) {
+               log_error("Device %s not found (or ignored by filtering).",
+                         pv_name);
+               return 0;
+       }
+
+       /*
+        * First, scan for LVM labels.
+        */
+       if (!label_read(dev, &label, label_sector)) {
+               log_error("Could not find LVM label on %s",
+                         pv_name);
+               return 0;
+       }
+
+       log_print("Found label on %s, sector %"PRIu64", type=%s",
+                 pv_name, label->sector, label->type);
+
+       return 1;
+}
index 288d17b0501e186ac03ee730f352dbcb99a99420..14f5df265ff721053993f706cb3980ca86d20556 100644 (file)
@@ -443,6 +443,8 @@ struct physical_volume *pv_create(const struct format_type *fmt,
                                  uint64_t pvmetadatasize, struct list *mdas);
 int pv_resize(struct physical_volume *pv, struct volume_group *vg,
               uint32_t new_pe_count);
+int pv_analyze(struct cmd_context *cmd, const char *pv_name,
+              int64_t label_sector);
 
 struct volume_group *vg_create(struct cmd_context *cmd, const char *name,
                               uint32_t extent_size, uint32_t max_pv,
index 1bf8692b3e84eced987b16a1e923835f92941be3..d92ae433259568369f3a129403ccf9e3ab056138 100644 (file)
@@ -3,11 +3,29 @@
 pvck \- check physical volume metadata
 .SH SYNOPSIS
 .B pvck
-[\-d/\-\-debug] [\-h/\-?/\-\-help] [\-v/\-\-verbose] [PhysicalVolume...]
+.RB [ \-d | \-\-debug ]
+.RB [ \-h | \-\-help ]
+.RB [ \-v | \-\-verbose ]
+.RB [ \-\-labelsector ]
+.IR PhysicalVolume " [" PhysicalVolume ...]
 .SH DESCRIPTION
 pvck checks physical volume LVM metadata for consistency.
 .SH OPTIONS
 See \fBlvm\fP for common options.
+.TP
+.BR \-\-labelsector " sector"
+By default, 4 sectors of \fBPhysicalVolume\fP are scanned for an LVM label,
+starting at sector 0.  This parameter allows you to specify a different
+starting sector for the scan and is useful for recovery situations.  For
+example, suppose the partition table is corrupted or lost on /dev/sda,
+but you suspect there was an LVM partition at approximately 100 MB.  This
+area of the disk may be scanned by using the \fB--labelsector\fP parameter
+with a value of 204800 (100 * 1024 * 1024 / 512 = 204800):
+.sp
+.BI "pvck --labelsector 204800 /dev/sda"
+.sp
+Note that a script can be used with \fB--labelsector\fP to automate the
+process of finding LVM labels.
 .SH SEE ALSO
 .BR lvm (8),
 .BR pvcreate (8),
index ba6136c20cd81de35675c29e6b845cbe06322cf2..c4a66f851a102141c8efab7a40dc50764f062dea 100644 (file)
@@ -412,9 +412,12 @@ xx(pvck,
    "pvck "
    "\t[-d|--debug]\n"
    "\t[-h|--help]\n"
+   "\t[--labelsector sector] " "\n"
    "\t[-v|--verbose]\n"
    "\t[--version]" "\n"
-   "\tPhysicalVolume [PhysicalVolume...]\n" )
+   "\tPhysicalVolume [PhysicalVolume...]\n",
+
+   labelsector_ARG)
 
 xx(pvcreate,
    "Initialize physical volume(s) for use by LVM",
index a928d0856eaa30d8cb8f58da7c843238f79bbc01..9baf87110d2d8046fba52faa34166e28c0bded77 100644 (file)
 
 #include "tools.h"
 
-static int _pvck_single(struct cmd_context * cmd,
-                       struct volume_group * vg,
-                       struct physical_volume * pv,
-                       void *handle)
-{
-       return ECMD_PROCESSED;
-}
-
 int pvck(struct cmd_context *cmd, int argc, char **argv)
 {
-       /* FIXME: Correlate findings of each PV */
-       return process_each_pv(cmd, argc, argv, NULL, NULL, _pvck_single);
+       int i;
+
+       /* FIXME: validate cmdline options */
+       /* FIXME: what does the cmdline look like? */
+       /*
+        * Use what's on the cmdline directly, and avoid calling into
+        * some of the other infrastructure functions, so as to avoid
+        * hitting some of the lvmcache behavior, scanning other devices,
+        * etc.
+        */
+       for (i = 0; i < argc; i++) {
+               /* FIXME: warning and/or check if in use? */
+               log_verbose("Scanning %s", argv[i]);
+
+               pv_analyze(cmd, argv[i],
+                          arg_int64_value(cmd, labelsector_ARG,
+                                          UINT64_C(0)));
+       }
+
+       return ECMD_PROCESSED;
 }
This page took 0.042632 seconds and 5 git commands to generate.