diff --git a/pkg/lvm/lvm.go b/pkg/lvm/lvm.go index 50c0c919..3c3fa690 100644 --- a/pkg/lvm/lvm.go +++ b/pkg/lvm/lvm.go @@ -850,6 +850,10 @@ func LookupPhysicalVolume(name string) (*PhysicalVolume, error) { // https://github.com/Jajcus/lvm2/blob/266d6564d7a72fcff5b25367b7a95424ccf8089e/lib/metadata/metadata.c#L983 func run(cmd string, v interface{}, extraArgs ...string) error { + if lvmlock != nil { + lvmlock.Lock() + defer lvmlock.Unlock() + } var args []string if v != nil { args = append(args, "--reportformat=json") diff --git a/pkg/lvm/lvm_test.go b/pkg/lvm/lvm_test.go index 66eeaca8..0c50ac80 100644 --- a/pkg/lvm/lvm_test.go +++ b/pkg/lvm/lvm_test.go @@ -4,6 +4,7 @@ package lvm import ( "fmt" + "io/ioutil" "reflect" "sort" "strings" @@ -18,6 +19,16 @@ const ( pvsize = 100 << 20 ) +func init() { + // Set the lock file to use in tests. + file, err := ioutil.TempFile("", "csilvm-test-lock-file") + if err != nil { + panic(err) + } + file.Close() + SetLockFilePath(file.Name()) +} + func TestCreatePhysicalDevice(t *testing.T) { loop, err := CreateLoopDevice(pvsize) if err != nil {