WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH] Fix a bug in tapctl.of_device

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH] Fix a bug in tapctl.of_device
From: David Scott <dave.scott@xxxxxxxxxxxxx>
Date: Mon, 23 Aug 2010 14:03:23 +0100
Delivery-date: Mon, 23 Aug 2010 06:26:01 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4.3
# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1282568582 -3600
# Node ID 81dbe94e62c30c70b15360a1c10418e2f6760e30
# Parent  0cf8a11ad69a7e2012384bf6b8e63b5f3fac8dc3
[Tapctl.of_device x] now will throw an exception if [x] is not a device; or if 
[x] is a device owned by another driver.

Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>

diff -r 0cf8a11ad69a -r 81dbe94e62c3 tapctl/tapctl.ml
--- a/tapctl/tapctl.ml  Mon Aug 23 14:02:39 2010 +0100
+++ b/tapctl/tapctl.ml  Mon Aug 23 14:03:02 2010 +0100
@@ -332,8 +332,24 @@
                | [(tapdev,state,Some _ )] -> true
                | _ -> false
 
+(* We need to be able to check that a given device's major number corresponds 
to the right driver *)
+let read_proc_devices () : (int * string) list = 
+       let parse_line x = match List.filter (fun x -> x <> "") (String.split ' 
' x) with
+       | [x; y] -> (try Some (int_of_string x, y) with _ -> None)
+       | _ -> None in
+       List.concat (List.map Opt.to_list ( Unixext.file_lines_fold (fun acc x 
-> parse_line x :: acc) [] "/proc/devices") )
+
+let driver_of_major major = List.assoc major (read_proc_devices ())
+
+exception Not_blktap
+exception Not_a_device
+
 let of_device ctx path =
-       let minor = (Unix.stat path).Unix.st_rdev mod 256 in
+       let stat = Unix.stat path in
+       if stat.Unix.st_kind <> Unix.S_BLK then raise Not_a_device;
+       let major = stat.Unix.st_rdev / 256 in
+       let minor = stat.Unix.st_rdev mod 256 in
+       if driver_of_major major <> "tapdev" then raise Not_blktap;
        match List.filter (fun (tapdev, _, _) -> tapdev.minor = minor) (list 
ctx) with
                | [ t ] -> t
                | _ -> raise Not_found
diff -r 0cf8a11ad69a -r 81dbe94e62c3 tapctl/tapctl.mli
--- a/tapctl/tapctl.mli Mon Aug 23 14:02:39 2010 +0100
+++ b/tapctl/tapctl.mli Mon Aug 23 14:03:02 2010 +0100
@@ -33,5 +33,11 @@
 val is_paused : context -> tapdev -> bool
 val is_active : context -> tapdev -> bool
 
+(** Thrown by [of_device x] when [x] is a device not owned by blktap *)
+exception Not_blktap
+
+(** Thrown by [of_device x] when [x] is not a device *)
+exception Not_a_device
+
 (** Given a path to a device, return the corresponding tap information *)
 val of_device : context -> string -> t
 tapctl/tapctl.ml  |  18 +++++++++++++++++-
 tapctl/tapctl.mli |   6 ++++++
 2 files changed, 23 insertions(+), 1 deletions(-)


Attachment: xen-api-libs.hg.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-API] [PATCH] Fix a bug in tapctl.of_device, David Scott <=