mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
This way the Lvm module contains only the OCaml implementations of LVM
daemon APIs.
This is simple refactoring, with no functional changes.
(cherry picked from commit 2bdc7b83ce)
49 lines
1.6 KiB
OCaml
49 lines
1.6 KiB
OCaml
(* 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
|