<commit_before>(*
 * Copyright (C) 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.
 *)
(**
 * @group Storage
 *)

let service_name="storage"

let default_sockets_dir = "/var/xapi"
let default_path = ref (Filename.concat default_sockets_dir service_name)

let set_sockets_dir x =
        default_path := Filename.concat x service_name

let uri () = "file:" ^ !default_path

open Vdi_automaton

(** Primary key identifying the SR *)
type sr = string

(** Primary key identifying a VDI within an SR *)
type vdi = string

(** Opaque identifier used by the client to identify a particular operation *)
type debug_info = string

(** The result of a successful VDI.attach: this information (eg) can be used to
	connect a VBD backend to a VBD frontend *)
type attach_info = {
	params : string;
	xenstore_data : (string * string) list;
}

(** Uniquely identifies the contents of a VDI *)
type content_id = string

(** The result of an operation which creates or examines a VDI *)
type vdi_info = {
    vdi: vdi;
	content_id: content_id;
    name_label: string;
    name_description: string;
    ty: string;
    (* sm_config: workaround via XenAPI *)
    metadata_of_pool: string;
    is_a_snapshot: bool;
    snapshot_time: string;
    snapshot_of: vdi;
    (* managed: workaround via XenAPI *)
    read_only: bool;
    (* missing: workaround via XenAPI *)
    virtual_size: int64;
    physical_utilisation: int64;
    (* xenstore_data: workaround via XenAPI *)
	persistent: bool;
    sm_config: (string * string) list;
}

let string_of_vdi_info (x: vdi_info) = Jsonrpc.to_string (rpc_of_vdi_info x)

(** Each VDI is associated with one or more "attached" or "activated" "datapaths". *)
type dp = string

type dp_stat_t = {
	superstate: Vdi_automaton.state;
	dps: (string * Vdi_automaton.state) list;
}

let string_of_dp_stat_t (x: dp_stat_t) = Jsonrpc.to_string (rpc_of_dp_stat_t x)

module Mirror = struct
	type id = string

	type state = 
		| Receiving
		| Sending

	type t = {
		source_vdi : vdi;
		dest_vdi : vdi;
		state : state list; 
		failed : bool;
	}

	type mirror_receive_result_vhd_t = {
		mirror_vdi : vdi_info;
		mirror_datapath : dp;
		copy_diffs_from : content_id option;
		copy_diffs_to : vdi;
		dummy_vdi : vdi;
	}
			
	type mirror_receive_result = 
		| Vhd_mirror of mirror_receive_result_vhd_t
			
	type similars = content_id list 
end

type async_result_t = 
	| Vdi_info of vdi_info
	| Mirror_id of Mirror.id



module Task = struct
	type id = string

	type async_result = async_result_t

	type completion_t = {
		duration : float;
		result : async_result option
	}

	type state =
		| Pending of float
		| Completed of completion_t
		| Failed of Rpc.t

	type t = {
		id: id;
		debug_info: string;
		ctime: float;
		state: state;
		subtasks: (string * state) list;
	}
end

module Dynamic = struct
	type id = 
		| Task of Task.id
		| Vdi of vdi
		| Dp of dp
		| Mirror of Mirror.id

	type t = 
		| Task_t of Task.id * Task.t
		| Vdi_t of vdi * vdi_info
		| Dp_t of dp * dp_stat_t
		| Mirror_t of Mirror.id * Mirror.t
		
end



exception Sr_not_attached of string               (** error: SR must be attached to access VDIs *)
exception Vdi_does_not_exist of string            (** error: the VDI is unknown *)
exception Illegal_transition of (Vdi_automaton.state * Vdi_automaton.state) (** This operation implies an illegal state transition *)
exception Backend_error of (string * (string list)) (** error: of the form SR_BACKEND_FAILURE *)
exception Does_not_exist of (string * string)
exception Cancelled of string
exception Redirect of string option
exception Sr_attached of string
exception Unimplemented of string
exception Duplicated_key of string
exception No_storage_plugin_for_sr of string
exception Missing_configuration_parameter of string

type query_result = {
	driver: string;
	name: string;
	description: string;
	vendor: string;
	copyright: string;
	version: string;
	required_api_version: string;
	features: string list;
	configuration: (string * string) list;
}

module Query = struct
	(** [query ()] returns information about this storage driver *)
	external query: dbg:string -> query_result = ""

	(** [diagnostics ()] returns diagnostic information about this storage driver *)
	external diagnostics: dbg:string -> string = ""
end
<commit_msg>Update storage:Query.query:features to be a list of pairs, matching xen-api interface change 37999467<commit_after>(*
 * Copyright (C) 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.
 *)
(**
 * @group Storage
 *)

let service_name="storage"

let default_sockets_dir = "/var/xapi"
let default_path = ref (Filename.concat default_sockets_dir service_name)

let set_sockets_dir x =
        default_path := Filename.concat x service_name

let uri () = "file:" ^ !default_path

open Vdi_automaton

(** Primary key identifying the SR *)
type sr = string

(** Primary key identifying a VDI within an SR *)
type vdi = string

(** Opaque identifier used by the client to identify a particular operation *)
type debug_info = string

(** The result of a successful VDI.attach: this information (eg) can be used to
	connect a VBD backend to a VBD frontend *)
type attach_info = {
	params : string;
	xenstore_data : (string * string) list;
}

(** Uniquely identifies the contents of a VDI *)
type content_id = string

(** The result of an operation which creates or examines a VDI *)
type vdi_info = {
    vdi: vdi;
	content_id: content_id;
    name_label: string;
    name_description: string;
    ty: string;
    (* sm_config: workaround via XenAPI *)
    metadata_of_pool: string;
    is_a_snapshot: bool;
    snapshot_time: string;
    snapshot_of: vdi;
    (* managed: workaround via XenAPI *)
    read_only: bool;
    (* missing: workaround via XenAPI *)
    virtual_size: int64;
    physical_utilisation: int64;
    (* xenstore_data: workaround via XenAPI *)
	persistent: bool;
    sm_config: (string * string) list;
}

let string_of_vdi_info (x: vdi_info) = Jsonrpc.to_string (rpc_of_vdi_info x)

(** Each VDI is associated with one or more "attached" or "activated" "datapaths". *)
type dp = string

type dp_stat_t = {
	superstate: Vdi_automaton.state;
	dps: (string * Vdi_automaton.state) list;
}

let string_of_dp_stat_t (x: dp_stat_t) = Jsonrpc.to_string (rpc_of_dp_stat_t x)

module Mirror = struct
	type id = string

	type state = 
		| Receiving
		| Sending

	type t = {
		source_vdi : vdi;
		dest_vdi : vdi;
		state : state list; 
		failed : bool;
	}

	type mirror_receive_result_vhd_t = {
		mirror_vdi : vdi_info;
		mirror_datapath : dp;
		copy_diffs_from : content_id option;
		copy_diffs_to : vdi;
		dummy_vdi : vdi;
	}
			
	type mirror_receive_result = 
		| Vhd_mirror of mirror_receive_result_vhd_t
			
	type similars = content_id list 
end

type async_result_t = 
	| Vdi_info of vdi_info
	| Mirror_id of Mirror.id



module Task = struct
	type id = string

	type async_result = async_result_t

	type completion_t = {
		duration : float;
		result : async_result option
	}

	type state =
		| Pending of float
		| Completed of completion_t
		| Failed of Rpc.t

	type t = {
		id: id;
		debug_info: string;
		ctime: float;
		state: state;
		subtasks: (string * state) list;
	}
end

module Dynamic = struct
	type id = 
		| Task of Task.id
		| Vdi of vdi
		| Dp of dp
		| Mirror of Mirror.id

	type t = 
		| Task_t of Task.id * Task.t
		| Vdi_t of vdi * vdi_info
		| Dp_t of dp * dp_stat_t
		| Mirror_t of Mirror.id * Mirror.t
		
end



exception Sr_not_attached of string               (** error: SR must be attached to access VDIs *)
exception Vdi_does_not_exist of string            (** error: the VDI is unknown *)
exception Illegal_transition of (Vdi_automaton.state * Vdi_automaton.state) (** This operation implies an illegal state transition *)
exception Backend_error of (string * (string list)) (** error: of the form SR_BACKEND_FAILURE *)
exception Does_not_exist of (string * string)
exception Cancelled of string
exception Redirect of string option
exception Sr_attached of string
exception Unimplemented of string
exception Duplicated_key of string
exception No_storage_plugin_for_sr of string
exception Missing_configuration_parameter of string

type query_result = {
	driver: string;
	name: string;
	description: string;
	vendor: string;
	copyright: string;
	version: string;
	required_api_version: string;
	features: (string * int64) list;
	configuration: (string * string) list;
}

module Query = struct
	(** [query ()] returns information about this storage driver *)
	external query: dbg:string -> query_result = ""

	(** [diagnostics ()] returns diagnostic information about this storage driver *)
	external diagnostics: dbg:string -> string = ""
end

{'fraction_non_alphanumeric': 0.08012422360248447, 'fraction_numerical': 0.003105590062111801, 'mean_word_length': 3.8719112455874938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '942905', 'n_tokens_mistral': 3261, 'n_tokens_neox': 3051, 'n_words': 1093}