Skip to content

Commit

Permalink
CP-45016: Implement get_nbd_server SMAPI{v1,v2,v3} calls
Browse files Browse the repository at this point in the history
This new function returns the real nbd server of the underlying storage
backend. This nbd server will not accept any fd passing. This is in
contrast to import_activate, which returns a "special" nbd server that
will accept fds via SCM_RIGHTS.

Signed-off-by: Vincent Liu <[email protected]>
  • Loading branch information
Vincent-lau committed Dec 10, 2024
1 parent 74297c3 commit b7a5124
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
26 changes: 24 additions & 2 deletions ocaml/xapi-idl/storage/storage_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,19 @@ module StorageAPI (R : RPC) = struct
@-> returning sock_path_p err
)


(** [get_nbd_server dbg dp sr vdi vm] returns the address of a generic nbd
server that can be connected to. Depending on the backend, this will either
be a nbd server backed by tapdisk or qemu-dp. Note this is different
from [import_activate] as the returned server does not accept fds. *)
let get_nbd_server =
declare "DATA.MIRROR.get_nbd_server" []
(dbg_p
@-> dp_p
@-> sr_p
@-> vdi_p
@-> vm_p
@-> returning sock_path_p err
)
end
end

Expand Down Expand Up @@ -1448,6 +1460,14 @@ module type Server_impl = sig
-> vm:vm
-> sock_path

val get_nbd_server :
context
-> dbg:debug_info
-> dp:dp
-> sr:sr
-> vdi:vdi
-> vm:vm
-> sock_path
end
end

Expand Down Expand Up @@ -1630,7 +1650,9 @@ module Server (Impl : Server_impl) () = struct
S.DATA.MIRROR.import_activate (fun dbg dp sr vdi vm ->
Impl.DATA.MIRROR.import_activate () ~dbg ~dp ~sr ~vdi ~vm
) ;

S.DATA.MIRROR.get_nbd_server (fun dbg dp sr vdi vm ->
Impl.DATA.MIRROR.get_nbd_server () ~dbg ~dp ~sr ~vdi ~vm
) ;
S.Policy.get_backend_vm (fun dbg vm sr vdi ->
Impl.Policy.get_backend_vm () ~dbg ~vm ~sr ~vdi
) ;
Expand Down
3 changes: 3 additions & 0 deletions ocaml/xapi-idl/storage/storage_skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ module DATA = struct

let import_activate ctx ~dbg ~dp ~sr ~vdi ~vm =
u "DATA.MIRROR.import_activate"

let get_nbd_server ctx ~dbg ~dp ~sr ~vdi ~vm =
u "DATA.MIRROR.get_nbd_server"
end
end

Expand Down
39 changes: 38 additions & 1 deletion ocaml/xapi-storage-script/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,44 @@ let bind ~volume_script_dir =
fail (Storage_interface.Errors.Unimplemented _vdi_mirror_in)
in
S.DATA.MIRROR.import_activate data_import_activate_impl ;

let get_nbd_server_impl dbg _dp sr vdi' vm' =
wrap
@@
let vdi = Storage_interface.Vdi.string_of vdi' in
let domain = Storage_interface.Vm.string_of vm' in
vdi_attach_common dbg sr vdi domain >>>= function
| response -> (
let convert_implementation = function
| Xapi_storage.Data.XenDisk {params; extra; backend_type} ->
Storage_interface.XenDisk {params; extra; backend_type}
| BlockDevice {path} ->
BlockDevice {path}
| File {path} ->
File {path}
| Nbd {uri} ->
Nbd {uri}
in
let _, blockdevices, _, nbds =
Storage_interface.implementations_of_backend
{
Storage_interface.implementations=
List.map convert_implementation
response.Xapi_storage.Data.implementations
}
in
match (blockdevices, nbds) with
| _, ({uri} as nbd) :: _ ->
info (fun m ->
m "%s qemu-dp nbd server address is %s" __FUNCTION__ uri
)
>>= fun () ->
let socket, _export = Storage_interface.parse_nbd_uri nbd in
return socket
| _ ->
fail (backend_error "No nbd server found" [])
)
in
S.DATA.MIRROR.get_nbd_server get_nbd_server_impl ;
let u name _ = failwith ("Unimplemented: " ^ name) in
S.get_by_name (u "get_by_name") ;
S.VDI.get_by_name (u "VDI.get_by_name") ;
Expand Down
9 changes: 8 additions & 1 deletion ocaml/xapi/storage_mux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,14 @@ module Mux = struct
end)) in
C.DATA.MIRROR.import_activate (Debug_info.to_string di) dp sr vdi vm


let get_nbd_server () ~dbg ~dp ~sr ~vdi ~vm =
with_dbg ~name:"DATA.MIRROR.get_nbd_server" ~dbg @@ fun di ->
info "%s dbg:%s dp:%s sr:%s vdi:%s vm:%s" __FUNCTION__ dbg dp
(s_of_sr sr) (s_of_vdi vdi) (s_of_vm vm) ;
let module C = StorageAPI (Idl.Exn.GenClient (struct
let rpc = of_sr sr
end)) in
C.DATA.MIRROR.get_nbd_server (Debug_info.to_string di) dp sr vdi vm
end
end

Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi/storage_smapiv1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ module SMAPIv1 : Server_impl = struct
let import_activate _context ~dbg:_ ~dp:_ ~sr:_ ~vdi:_ ~vm:_ =
assert false

let get_nbd_server _context ~dbg:_ ~dp:_ ~sr:_ ~vdi:_ ~vm:_ = assert false
end
end

Expand Down
3 changes: 3 additions & 0 deletions ocaml/xapi/storage_smapiv1_wrapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ functor

let import_activate context ~dbg ~dp ~sr ~vdi ~vm =
get_nbd_server_common context ~dbg ~dp ~sr ~vdi ~vm ~style:`oldstyle

let get_nbd_server context ~dbg ~dp ~sr ~vdi ~vm =
get_nbd_server_common context ~dbg ~dp ~sr ~vdi ~vm ~style:`real
end
end

Expand Down

0 comments on commit b7a5124

Please sign in to comment.