mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: move Lvm.lv_canonical to new Lvm_utils module
This way the Lvm module contains only the OCaml implementations of LVM daemon APIs. This is simple refactoring, with no functional changes.
This commit is contained in:
@@ -268,6 +268,7 @@ SOURCES_MLI = \
|
||||
link.mli \
|
||||
listfs.mli \
|
||||
lvm.mli \
|
||||
lvm_utils.mli \
|
||||
md.mli \
|
||||
mount.mli \
|
||||
mountable.mli \
|
||||
@@ -296,6 +297,7 @@ SOURCES_ML = \
|
||||
ldm.ml \
|
||||
link.ml \
|
||||
lvm.ml \
|
||||
lvm_utils.ml \
|
||||
findfs.ml \
|
||||
md.ml \
|
||||
mount.ml \
|
||||
|
||||
@@ -44,7 +44,7 @@ and findfs tag str =
|
||||
|
||||
if String.is_prefix out "/dev/mapper/" ||
|
||||
String.is_prefix out "/dev/dm-" then (
|
||||
match Lvm.lv_canonical out with
|
||||
match Lvm_utils.lv_canonical out with
|
||||
| None ->
|
||||
(* Ignore the case where 'out' doesn't appear to be an LV.
|
||||
* The best we can do is return the original as-is.
|
||||
|
||||
@@ -327,7 +327,7 @@ and resolve_fstab_device spec md_map os_type =
|
||||
* we have implemented lvm_canonical_lv_name in the daemon.
|
||||
*)
|
||||
try
|
||||
match Lvm.lv_canonical spec with
|
||||
match Lvm_utils.lv_canonical spec with
|
||||
| None -> Mountable.of_device spec
|
||||
| Some device -> Mountable.of_device device
|
||||
with
|
||||
|
||||
@@ -97,30 +97,3 @@ and filter_convert_old_lvs_output out =
|
||||
) lines in
|
||||
|
||||
List.sort compare lines
|
||||
|
||||
(* Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0
|
||||
* to a canonical one.
|
||||
*
|
||||
* This is harder than it should be. A LV device like /dev/VG/LV is
|
||||
* really a symlink to a device-mapper device like /dev/dm-0. However
|
||||
* at the device-mapper (kernel) level, nothing is really known about
|
||||
* LVM (a userspace concept). Therefore we use a convoluted method to
|
||||
* determine this, by listing out known LVs and checking whether the
|
||||
* rdev (major/minor) of the device we are passed matches any of them.
|
||||
*
|
||||
* Note use of 'stat' instead of 'lstat' so that symlinks are fully
|
||||
* resolved.
|
||||
*)
|
||||
let lv_canonical device =
|
||||
let stat1 = stat device in
|
||||
let lvs = lvs () in
|
||||
try
|
||||
Some (
|
||||
List.find (
|
||||
fun lv ->
|
||||
let stat2 = stat lv in
|
||||
stat1.st_rdev = stat2.st_rdev
|
||||
) lvs
|
||||
)
|
||||
with
|
||||
| Not_found -> None
|
||||
|
||||
@@ -17,13 +17,3 @@
|
||||
*)
|
||||
|
||||
val lvs : unit -> string list
|
||||
|
||||
val lv_canonical : string -> string option
|
||||
(** Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0
|
||||
to a canonical one.
|
||||
|
||||
On error this raises an exception. There are two possible non-error
|
||||
return cases:
|
||||
|
||||
Some lv = conversion was successful, returning the canonical LV
|
||||
None = input path was not an LV, it could not be made canonical *)
|
||||
|
||||
48
daemon/lvm_utils.ml
Normal file
48
daemon/lvm_utils.ml
Normal file
@@ -0,0 +1,48 @@
|
||||
(* guestfs-inspection
|
||||
* Copyright (C) 2009-2018 Red Hat Inc.
|
||||
*
|
||||
* This program 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 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
open Unix
|
||||
|
||||
open Utils
|
||||
|
||||
(* Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0
|
||||
* to a canonical one.
|
||||
*
|
||||
* This is harder than it should be. A LV device like /dev/VG/LV is
|
||||
* really a symlink to a device-mapper device like /dev/dm-0. However
|
||||
* at the device-mapper (kernel) level, nothing is really known about
|
||||
* LVM (a userspace concept). Therefore we use a convoluted method to
|
||||
* determine this, by listing out known LVs and checking whether the
|
||||
* rdev (major/minor) of the device we are passed matches any of them.
|
||||
*
|
||||
* Note use of 'stat' instead of 'lstat' so that symlinks are fully
|
||||
* resolved.
|
||||
*)
|
||||
let lv_canonical device =
|
||||
let stat1 = stat device in
|
||||
let lvs = Lvm.lvs () in
|
||||
try
|
||||
Some (
|
||||
List.find (
|
||||
fun lv ->
|
||||
let stat2 = stat lv in
|
||||
stat1.st_rdev = stat2.st_rdev
|
||||
) lvs
|
||||
)
|
||||
with
|
||||
| Not_found -> None
|
||||
27
daemon/lvm_utils.mli
Normal file
27
daemon/lvm_utils.mli
Normal file
@@ -0,0 +1,27 @@
|
||||
(* guestfs-inspection
|
||||
* Copyright (C) 2009-2018 Red Hat Inc.
|
||||
*
|
||||
* This program 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 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
val lv_canonical : string -> string option
|
||||
(** Convert a non-canonical LV path like /dev/mapper/vg-lv or /dev/dm-0
|
||||
to a canonical one.
|
||||
|
||||
On error this raises an exception. There are two possible non-error
|
||||
return cases:
|
||||
|
||||
Some lv = conversion was successful, returning the canonical LV
|
||||
None = input path was not an LV, it could not be made canonical *)
|
||||
Reference in New Issue
Block a user