Skip to contentSkip to conversation

cannot create PV on empty drive

PATCH In review Jerome Borsboom 2 participants 3 messages Dec 16, 2004 – Dec 21, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cannot create PV on empty drive

While I was checking out LVM, I ran into a problem with the 2.00.31 version of LVM2. When I tried to create a new PV on /dev/sdb, pvcreate failed and went into an infinite loop trying to close a file-descriptor. This only happened when no .cache file was present in /etc/lvm and only on /dev/sdb, i.e. /dev/sdb1 did work.

Some debugging showed that the culprit was the recent change to the dev_open_flags code. The problem seems to be the reopening of the fd in RW mode without closing the old RO one. The patch below solved the problem for me, but I did not give it very much testing. Hope this helps.

Greetz,

Jerome Borsboom

lib/device/dev-io.c 2004-12-16 17:03:09.503357553 +0100 renamed from lib/device/dev-io.c 2004-12-12 22:47:14.000000000 +0100 +8 -7
diff -ru LVM2.2.00.31/lib/device/dev-io.c LVM2.2.00.31.new/lib/device/dev-io.c
@@ -292,6 +292,7 @@
 {
        struct stat buf;
        const char *name;
+       int old_open_count = 0;
 
        if (dev->fd >= 0) {
                if ((dev->flags & DEV_OPENED_RW) ||
@@ -299,12 +300,12 @@
                        dev->open_count++;
                        return 1;
                }
-
-               if (dev->open_count)
-                       log_debug("WARNING: %s already opened read-only",
-                                 dev_name(dev));
-               else
-                       dev_close_immediate(dev);
+               else {
+                       if (dev->open_count)
+                               log_debug("WARNING: %s already opened read-only",
+                                         dev_name(dev));
+                       old_open_count = dev->open_count;
+                       dev_close_immediate(dev); }
        }
 
        if (memlock())
@@ -340,7 +341,7 @@
                return 0;
        }
 
-       dev->open_count = 1;
+       dev->open_count = old_open_count + 1;
        dev->flags &= ~DEV_ACCESSED_W;
        if ((flags & O_ACCMODE) == O_RDWR)
                dev->flags |= DEV_OPENED_RW;
#1 lore raw

Do you have verbose output from the failing pvcreate with '-vvvv'? (or debug-log-to-file output)

Quoted 2 lines · Jerome Borsboom

Some debugging showed that the culprit was the recent change to the dev_open_flags code.

The patch was produced under severe time pressure before I went away and I know it doesn't deal with one case properly - maybe the case you hit. It addresses a symptom not the cause: the code is not meant to be trying to write to read-only file descriptors in the first place, and this happens here because of a shortcoming in way it does its locking. I'll deal with this maybe later this week or else in the New Year.

Alasdair

Signature · 1 line
[email protected]
#2 lore raw
Quoted 2 lines · Alasdair G Kergon

Do you have verbose output from the failing pvcreate with '-vvvv'? (or debug-log-to-file output)

I still don't know how to reproduce this.

Meanwhile, I'm checking in a patch based on yours.

Alasdair

Signature · 1 line
[email protected]