~ubuntu-branches/ubuntu/quantal/xen-api/quantal

« back to all changes in this revision

Viewing changes to ocaml/xapi/static_vdis_list.ml

  • Committer: Package Import Robot
  • Author(s): Jon Ludlam
  • Date: 2011-07-07 21:50:18 UTC
  • Revision ID: package-import@ubuntu.com-20110707215018-3t9ekbh7qy5y2b1p
Tags: upstream-1.3
ImportĀ upstreamĀ versionĀ 1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * Copyright (C) 2006-2009 Citrix Systems Inc.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation; version 2.1 only. with the special
 
7
 * exception on linking described in file LICENSE.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU Lesser General Public License for more details.
 
13
 *)
 
14
(**
 
15
 * @group Storage
 
16
 *)
 
17
 
 
18
(** Represents the configuration of a static (ie attached on boot) vdi *)
 
19
type vdi = {
 
20
  uuid:               string;        (* VDI.uuid *)
 
21
  reason:             string;        (* describes why this disk was attached for debugging *)
 
22
  delete_next_boot:   bool;          (* indicates this disk configuration will be forgotten on reboot *)
 
23
  currently_attached: bool;          (* indicates this disk is attached now in dom0 *)
 
24
  path:               string option; (* path in dom0 *)
 
25
}
 
26
 
 
27
(** Returns a list of vdi records, one for each VDI statically configured on this host *)
 
28
let list () = 
 
29
  (* Read the filesystem structure directly *)
 
30
  let main_dir = "/etc/xensource/static-vdis" in
 
31
  let all = try Array.to_list (Sys.readdir main_dir) with Sys_error _ -> [] in
 
32
  List.map (fun x ->
 
33
              let path = Filename.concat main_dir x in
 
34
              let uuid = Unixext.string_of_file (Filename.concat path "vdi-uuid") in
 
35
              let reason = Unixext.string_of_file (Filename.concat path "reason") in
 
36
              (* let bool_of_string x = String.lowercase x = "true" in *)
 
37
              let delete_next_boot = 
 
38
                try ignore(Unix.stat (Filename.concat path "delete-next-boot")); true 
 
39
                with _ -> false in
 
40
              let currently_attached = 
 
41
                try ignore(Unix.stat (Filename.concat path "disk")); true 
 
42
                with _ -> false in
 
43
              let path = 
 
44
                try Some (Unix.readlink (Filename.concat path "disk"))
 
45
                with _ -> None in
 
46
              { uuid = uuid; reason = reason; delete_next_boot = delete_next_boot;
 
47
                currently_attached = currently_attached; path = path }) all
 
48