<commit_before>(*
 * Copyright (C) 2006-2011 Citrix Systems Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * 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 Lesser General Public License for more details.
 *)
open Threadext
open Stringext
module XenAPI = Client.Client
open Fun
open Storage_interface

module D=Debug.Debugger(struct let name="storage_access" end)
open D

exception No_VDI

(* Find a VDI given a storage-layer SR and VDI *)
let find_vdi ~__context sr vdi =
	let open Db_filter_types in
	let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
	match Db.VDI.get_records_where ~__context ~expr:(And((Eq (Field "location", Literal vdi)),Eq (Field "SR", Literal (Ref.string_of sr)))) with
		| x :: _ -> x
		| _ -> raise No_VDI

(* Find a VDI reference given a name *)
let find_content ~__context ?sr name =
	(* PR-1255: the backend should do this for us *)
	let open Db_filter_types in
	let expr = Opt.default True (Opt.map (fun sr -> Eq(Field "SR", Literal (Ref.string_of (Db.SR.get_by_uuid ~__context ~uuid:sr)))) sr) in
	let all = Db.VDI.get_records_where ~__context ~expr in
	List.find
		(fun (_, vdi_rec) ->
			false
			|| (vdi_rec.API.vDI_location = name) (* PR-1255 *)
			|| (List.mem_assoc "content_id" vdi_rec.API.vDI_other_config && (List.assoc "content_id" vdi_rec.API.vDI_other_config = name))
		) all

let redirect sr =
	raise (Redirect (Some (Pool_role.get_master_address ())))

module SMAPIv1 = struct
	(** xapi's builtin ability to call local SM plugins using the existing
	    protocol. The code here should only call the SM functions and encapsulate
	    the return or error properly. It should not perform side-effects on
	    the xapi database: these should be handled in the layer above so they
	    can be shared with other SM implementation types.

	    Where this layer has to perform interface adjustments (see VDI.activate
	    and the read/write debacle), this highlights desirable improvements to
	    the backend interface.
	*)

	type context = Smint.request

	module Query = struct
		let query context ~dbg = {
			driver = "storage_access";
			name = "SMAPIv1 adapter";
			description = "Allows legacy SMAPIv1 adapters to expose an SMAPIv2 interface";
			vendor = "XCP";
			copyright = "see the source code";
			version = "2.0";<commit_msg>[sm] VDI.get_by_name should not look up by content_id<commit_after>(*
 * Copyright (C) 2006-2011 Citrix Systems Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * 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 Lesser General Public License for more details.
 *)
open Threadext
open Stringext
module XenAPI = Client.Client
open Fun
open Storage_interface

module D=Debug.Debugger(struct let name="storage_access" end)
open D

exception No_VDI

(* Find a VDI given a storage-layer SR and VDI *)
let find_vdi ~__context sr vdi =
	let open Db_filter_types in
	let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
	match Db.VDI.get_records_where ~__context ~expr:(And((Eq (Field "location", Literal vdi)),Eq (Field "SR", Literal (Ref.string_of sr)))) with
		| x :: _ -> x
		| _ -> raise No_VDI

(* Find a VDI reference given a name *)
let find_content ~__context ?sr name =
	(* PR-1255: the backend should do this for us *)
	let open Db_filter_types in
	let expr = Opt.default True (Opt.map (fun sr -> Eq(Field "SR", Literal (Ref.string_of (Db.SR.get_by_uuid ~__context ~uuid:sr)))) sr) in
	let all = Db.VDI.get_records_where ~__context ~expr in
	List.find
		(fun (_, vdi_rec) ->
			false
			|| (vdi_rec.API.vDI_location = name) (* PR-1255 *)
		) all

let redirect sr =
	raise (Redirect (Some (Pool_role.get_master_address ())))

module SMAPIv1 = struct
	(** xapi's builtin ability to call local SM plugins using the existing
	    protocol. The code here should only call the SM functions and encapsulate
	    the return or error properly. It should not perform side-effects on
	    the xapi database: these should be handled in the layer above so they
	    can be shared with other SM implementation types.

	    Where this layer has to perform interface adjustments (see VDI.activate
	    and the read/write debacle), this highlights desirable improvements to
	    the backend interface.
	*)

	type context = Smint.request

	module Query = struct
		let query context ~dbg = {
			driver = "storage_access";
			name = "SMAPIv1 adapter";
			description = "Allows legacy SMAPIv1 adapters to expose an SMAPIv2 interface";
			vendor = "XCP";
			copyright = "see the source code";
			version = "2.0";
{'fraction_non_alphanumeric': 0.08358778625954198, 'fraction_numerical': 0.00916030534351145, 'mean_word_length': 3.870817843866171, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3193710', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1552, 'n_words': 663}