[PATCHSET 00/18] open-osd: OSD Initiator library for Linux - Kernel

This is a discussion on [PATCHSET 00/18] open-osd: OSD Initiator library for Linux - Kernel ; Boaz Harrosh wrote: > Sam Ravnborg wrote: >>> +EXPORT_SYMBOL(osd_dev_init); >> kernel-doc comments for all exported funtions / variables. >> > > I have some kernel-doc comments of exported functions in the Header > file. I have not yet finished all ...

+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3
Results 41 to 53 of 53

Thread: [PATCHSET 00/18] open-osd: OSD Initiator library for Linux

  1. Re: [osd-dev] [PATCH 04/18] libosd: OSDv1 preliminary implementation

    Boaz Harrosh wrote:
    > Sam Ravnborg wrote:
    >>> +EXPORT_SYMBOL(osd_dev_init);

    >> kernel-doc comments for all exported funtions / variables.
    >>

    >
    > I have some kernel-doc comments of exported functions in the Header
    > file. I have not yet finished all of them. (Laziness on my part).
    >
    > Are kernel-doc comments in headers a big NO-NO. I like it this way,
    > so when I have to learn a new Library all the information
    > I need to know is in the header. Also the header is a much better place
    > when you do programing by shopping, that is you don't know what you need
    > and you look for what's available.
    >
    > Thanks
    > Boaz


    Sam please comment if kernel-doc comments are OK in headers

    Thanks
    Boaz
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  2. [PATCH 03/18 ver2] libosd: OSDv1 Headers


    Headers only patch.

    osd_protocol.h
    Contains a C-fied definition of the T10 OSD standard
    osd_types.h
    Contains CPU order common used types
    osd_initiator.h
    API definition of the osd_initiator library
    osd_sec.h
    Contains High level API for the security manager.

    [Note that checkpatch spews errors on things that are valid in this context
    and will not be fixed]

    Signed-off-by: Boaz Harrosh
    Reviewed-by: Benny Halevy
    ---
    include/scsi/osd_initiator.h | 332 ++++++++++++++++++++++++++++
    include/scsi/osd_protocol.h | 497 ++++++++++++++++++++++++++++++++++++++++++
    include/scsi/osd_sec.h | 45 ++++
    include/scsi/osd_types.h | 40 ++++
    4 files changed, 914 insertions(+), 0 deletions(-)
    create mode 100644 include/scsi/osd_initiator.h
    create mode 100644 include/scsi/osd_protocol.h
    create mode 100644 include/scsi/osd_sec.h
    create mode 100644 include/scsi/osd_types.h

    diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h
    new file mode 100644
    index 0000000..9bab95d
    --- /dev/null
    +++ b/include/scsi/osd_initiator.h
    @@ -0,0 +1,332 @@
    +/*
    + * osd_initiator.h - OSD initiator API definition
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + */
    +#ifndef __OSD_INITIATOR_H__
    +#define __OSD_INITIATOR_H__
    +
    +#include "osd_protocol.h"
    +#include "osd_types.h"
    +
    +#include
    +
    +/* Note: "NI" in comments below means "Not Implemented yet" */
    +
    +/*
    + * Object-based Storage Device.
    + * This object represents an OSD device.
    + * It is not a full linux device in any way. It is only
    + * a place to hang resources associated with a Linux
    + * request Q and some default properties.
    + */
    +struct osd_dev {
    + struct scsi_device *scsi_device;
    + unsigned def_timeout;
    +};
    +
    +void osd_dev_init(struct osd_dev *, struct scsi_device *scsi_dev);
    +void osd_dev_fini(struct osd_dev *);
    +
    +struct osd_request;
    +typedef void (osd_req_done_fn)(struct osd_request *, void *);
    +
    +struct osd_request {
    + struct osd_cdb cdb;
    + struct osd_data_out_integrity_info out_data_integ;
    + struct osd_data_in_integrity_info in_data_integ;
    +
    + struct osd_dev *osd_dev;
    + struct request *request;
    +
    + struct _osd_req_data_segment {
    + void *buff;
    + unsigned alloc_size; /* 0 here means not allocated by us */
    + unsigned total_bytes;
    + } set_attr, enc_get_attr, get_attr;
    +
    + struct _osd_io_info {
    + struct bio *bio;
    + u64 total_bytes;
    + struct request *req;
    + struct _osd_req_data_segment *last_seg;
    + u8 *pad_buff;
    + } out, in;
    +
    + gfp_t alloc_flags;
    + unsigned timeout;
    + unsigned retries;
    + u8 sense[OSD_MAX_SENSE_LEN];
    + enum osd_attributes_mode attributes_mode;
    +
    + osd_req_done_fn *async_done;
    + void *async_private;
    + int async_error;
    +};
    +
    +/**
    + * How to use the osd library:
    + *
    + * osd_start_request
    + * Allocates a request.
    + *
    + * osd_req_*
    + * Call one of, to encode the desired operation.
    + *
    + * osd_add_{get,set}_attr
    + * Optionally add attributes to the CDB, list or page mode.
    + *
    + * osd_finalize_request
    + * Computes final data out/in offsets and signs the request,
    + * making it ready for execution.
    + *
    + * osd_execute_request
    + * May be called to execute it through the block layer. Other wise submit
    + * the associated block request in some other way.
    + *
    + * After execution:
    + * osd_req_decode_sense
    + * Decodes sense information to verify execution results.
    + *
    + * osd_req_decode_get_attr
    + * Retrieve osd_add_get_attr_list() values if used.
    + *
    + * osd_end_request
    + * Must be called to deallocate the request.
    + */
    +
    +/**
    + * osd_start_request - Allocate and initialize an osd_request
    + *
    + * @osd_dev: OSD device that holds the scsi-device and default values
    + * that the request is associated with.
    + * @gfp: The allocation flags to use for request allocation, and all
    + * subsequent allocations. This will be stored at
    + * osd_request->alloc_flags, can be changed by user later
    + *
    + * Allocate osd_request and initialize all members to the
    + * default/initial state.
    + */
    +struct osd_request *osd_start_request(struct osd_dev *, gfp_t gfp);
    +
    +enum osd_req_options {
    + OSD_REQ_FUA = 0x08, /* Force Unit Access */
    + OSD_REQ_DPO = 0x10, /* Disable Page Out */
    +
    + OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
    +};
    +
    +/**
    + * osd_finalize_request - Sign request and prepare request for execution
    + *
    + * @or: osd_request to prepare
    + * @options: combination of osd_req_options bit flags or 0.
    + * @cap A Pointer to an OSD_CAP_LEN bytes buffer that is received from
    + * The security manager as capabilities for this cdb.
    + * @cap_key The cryptographic key used to sign the cdb/data. Can be null
    + * if NOSEC is used.
    + *
    + * The actual request and bios are only allocated here, so are the get_attr
    + * buffers that will receive the returned attributes. Copy's @cap to cdb.
    + * Sign the cdb/data with @cap_key.
    + */
    +int osd_finalize_request(struct osd_request *or,
    + u8 options, const void *cap, const u8 *cap_key);
    +
    +/**
    + * osd_execute_request - Execute the request synchronously through
    + * the block-layer
    + * @or: osd_request to Executed
    + *
    + * Calls blk_execute_rq to q the command and waits for completion.
    + */
    +int osd_execute_request(struct osd_request *or);
    +
    +/**
    + * osd_execute_request_async - submits the request for execution through
    + * the block-layer without waitting.
    + * @or: - osd_request to Executed
    + * @done: (Optional) - Called at end of execution
    + * @private: - Will be passes to @done function
    + *
    + * Calls blk_execute_rq_nowait to q the command. When execution is done
    + * Optionally calles @done with @private as parameter. or->async_error has the
    + * Return code
    + */
    +int osd_execute_request_async(struct osd_request *or,
    + osd_req_done_fn *done, void *private);
    +
    +/**
    + * osd_end_request - return osd_request to free store
    + *
    + * @or: osd_request to free
    + *
    + * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.)
    + */
    +void osd_end_request(struct osd_request *or);
    +
    +/*
    + * CDB Encoding
    + *
    + * Note: call only one of the following methods.
    + */
    +
    +/*
    + * Device commands
    + */
    +void osd_req_set_master_seed_xchg(struct osd_request *, ...);/* NI */
    +void osd_req_set_master_key(struct osd_request *, ...);/* NI */
    +
    +void osd_req_format(struct osd_request *, u64 tot_capacity);
    +
    +/* list all partitions
    + * @list header must be initialized to zero on first run.
    + *
    + * Call osd_is_obj_list_done() to find if we got the complete list.
    + */
    +int osd_req_list_dev_partitions(struct osd_request *,
    + osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
    +
    +void osd_req_flush_obsd(struct osd_request *,
    + enum osd_options_flush_scope_values);
    +
    +void osd_req_perform_scsi_command(struct osd_request *,
    + const u8 *cdb, ...);/* NI */
    +void osd_req_task_management(struct osd_request *, ...);/* NI */
    +
    +/*
    + * Partition commands
    + */
    +void osd_req_create_partition(struct osd_request *, osd_id partition);
    +void osd_req_remove_partition(struct osd_request *, osd_id partition);
    +
    +void osd_req_set_partition_key(struct osd_request *,
    + osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
    + u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */
    +
    +/* list all collections in the partition
    + * @list header must be init to zero on first run.
    + *
    + * Call osd_is_obj_list_done() to find if we got the complete list.
    + */
    +int osd_req_list_partition_collections(struct osd_request *,
    + osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
    + unsigned nelem);
    +
    +/* list all objects in the partition
    + * @list header must be init to zero on first run.
    + *
    + * Call osd_is_obj_list_done() to find if we got the complete list.
    + */
    +int osd_req_list_partition_objects(struct osd_request *,
    + osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
    + unsigned nelem);
    +
    +void osd_req_flush_partition(struct osd_request *,
    + osd_id partition, enum osd_options_flush_scope_values);
    +
    +/*
    + * Collection commands
    + */
    +void osd_req_create_collection(struct osd_request *,
    + const struct osd_obj_id *);/* NI */
    +void osd_req_remove_collection(struct osd_request *,
    + const struct osd_obj_id *);/* NI */
    +
    +/* list all objects in the collection */
    +int osd_req_list_collection_objects(struct osd_request *,
    + const struct osd_obj_id *, osd_id initial_id,
    + struct osd_obj_id_list *list, unsigned nelem);
    +
    +/* V2 only filtered list of objects in the collection */
    +void osd_req_query(struct osd_request *, ...);/* NI */
    +
    +void osd_req_flush_collection(struct osd_request *,
    + const struct osd_obj_id *, enum osd_options_flush_scope_values);
    +
    +void osd_req_get_member_attrs(struct osd_request *, ...);/* V2-only NI */
    +void osd_req_set_member_attrs(struct osd_request *, ...);/* V2-only NI */
    +
    +/*
    + * Object commands
    + */
    +void osd_req_create_object(struct osd_request *, struct osd_obj_id *);
    +void osd_req_remove_object(struct osd_request *, struct osd_obj_id *);
    +
    +void osd_req_write(struct osd_request *,
    + const struct osd_obj_id *, struct bio *data_out, u64 offset);
    +void osd_req_append(struct osd_request *,
    + const struct osd_obj_id *, struct bio *data_out);/* NI */
    +void osd_req_create_write(struct osd_request *,
    + const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */
    +void osd_req_clear(struct osd_request *,
    + const struct osd_obj_id *, u64 offset, u64 len);/* NI */
    +void osd_req_punch(struct osd_request *,
    + const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */
    +
    +void osd_req_flush_object(struct osd_request *,
    + const struct osd_obj_id *, enum osd_options_flush_scope_values,
    + /*V2*/ u64 offset, /*V2*/ u64 len);
    +
    +void osd_req_read(struct osd_request *,
    + const struct osd_obj_id *, struct bio *data_in, u64 offset);
    +
    +/*
    + * Root/Partition/Collection/Object Attributes commands
    + */
    +
    +/* get before set */
    +void osd_req_get_attributes(struct osd_request *, const struct osd_obj_id *);
    +
    +/* set before get */
    +void osd_req_set_attributes(struct osd_request *, const struct osd_obj_id *);
    +
    +/*
    + * Attributes appended to most commands
    + */
    +
    +/* Attributes List mode (or V2 CDB) */
    + /*
    + * TODO: In ver2 if at finalize time only one attr was set and no gets,
    + * then the Attributes CDB mode is used automatically to save IO.
    + */
    +
    +/* set a list of attributes. */
    +int osd_req_add_set_attr_list(struct osd_request *,
    + const struct osd_attr *, unsigned nelem);
    +
    +/* get a list of attributes */
    +int osd_req_add_get_attr_list(struct osd_request *,
    + const struct osd_attr *, unsigned nelem);
    +
    +/*
    + * Attributes list decoding
    + * Must be called after osd_request.request was executed
    + * It is called in a loop to decode the returned get_attr
    + * (see osd_add_get_attr)
    + */
    +int osd_req_decode_get_attr_list(struct osd_request *,
    + struct osd_attr *, int *nelem, void **iterator);
    +
    +/* Attributes Page mode */
    +
    +/*
    + * Read an attribute page and optionally set one attribute
    + *
    + * Retrieves the attribute page directly to a user buffer.
    + * @attr_page_data shall stay valid until end of execution.
    + * See osd_attributes.h for common page structures
    + */
    +int osd_req_add_get_attr_page(struct osd_request *,
    + u32 page_id, void *attr_page_data, unsigned max_page_len,
    + const struct osd_attr *set_one);
    +
    +#endif /* __OSD_LIB_H__ */
    diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h
    new file mode 100644
    index 0000000..77a74a3
    --- /dev/null
    +++ b/include/scsi/osd_protocol.h
    @@ -0,0 +1,497 @@
    +/*
    + * osd_protocol.h - OSD T10 standard C definitions.
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + * This file contains types and constants that are defined by the protocol
    + * Note: All names and symbols are taken from the OSD standard's text.
    + */
    +#ifndef __OSD_PROTOCOL_H__
    +#define __OSD_PROTOCOL_H__
    +
    +#include
    +#include
    +#include
    +
    +enum {
    + OSDv1_ADDITIONAL_CDB_LENGTH = 192,
    + OSDv1_TOTAL_CDB_LEN = OSDv1_ADDITIONAL_CDB_LENGTH + 8,
    + OSDv1_CAP_LEN = 80,
    + /* Latest supported version */
    + OSD_ADDITIONAL_CDB_LENGTH = OSDv1_ADDITIONAL_CDB_LENGTH,
    + OSD_TOTAL_CDB_LEN = OSDv1_TOTAL_CDB_LEN,
    + OSD_CAP_LEN = OSDv1_CAP_LEN,
    +
    + OSD_SYSTEMID_LEN = 20,
    + OSD_CRYPTO_KEYID_SIZE = 20,
    + OSD_CRYPTO_SEED_SIZE = 4,
    + OSD_CRYPTO_NONCE_SIZE = 12,
    + OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */
    +
    + OSD_PARTITION_FIRST_ID = 0x10000,
    + OSD_OBJECT_FIRST_ID = 0x10000,
    +};
    +
    +/* (osd-r10 5.2.4)
    + * osd2r03: 5.2.3 Caching control bits
    + */
    +enum osd_options_byte {
    + OSD_CDB_FUA = 0x08, /* Force Unit Access */
    + OSD_CDB_DPO = 0x10, /* Disable Page Out */
    +};
    +
    +/*
    + * osd2r03: 5.2.5 Isolation.
    + * First 3 bits, V2-only.
    + * Also for attr 110h "default isolation method" at Root Information page
    + */
    +enum osd_options_byte_isolation {
    + OSD_ISOLATION_DEFAULT = 0,
    + OSD_ISOLATION_NONE = 1,
    + OSD_ISOLATION_STRICT = 2,
    + OSD_ISOLATION_RANGE = 4,
    + OSD_ISOLATION_FUNCTIONAL = 5,
    + OSD_ISOLATION_VENDOR = 7,
    +};
    +
    +/* (osd-r10: 6.7)
    + * osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
    + */
    +enum osd_options_flush_scope_values {
    + OSD_CDB_FLUSH_ALL = 0,
    + OSD_CDB_FLUSH_ATTR_ONLY = 1,
    +
    + OSD_CDB_FLUSH_ALL_RECURSIVE = 2,
    + /* V2-only */
    + OSD_CDB_FLUSH_ALL_RANGE = 2,
    +};
    +
    +/* osd2r03: 5.2.10 Timestamps control */
    +enum {
    + OSD_CDB_NORMAL_TIMESTAMPS = 0,
    + OSD_CDB_BYPASS_TIMESTAMPS = 0x7f,
    +};
    +
    +/* (osd-r10: 5.2.2.1)
    + * osd2r03: 5.2.4.1 Get and set attributes CDB format selection
    + * 2 bits at second nibble of command_specific_options byte
    + */
    +enum osd_attributes_mode {
    + /* V2-only */
    + OSD_CDB_SET_ONE_ATTR = 0x10,
    +
    + OSD_CDB_GET_ATTR_PAGE_SET_ONE = 0x20,
    + OSD_CDB_GET_SET_ATTR_LISTS = 0x30,
    +
    + OSD_CDB_GET_SET_ATTR_MASK = 0x30,
    +};
    +
    +/* (osd-r10: 4.12.5)
    + * osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
    + * byte offset = mantissa * (2^(exponent+8))
    + * struct {
    + * unsigned mantissa: 28;
    + * int exponent: 04;
    + * }
    + */
    +typedef __be32 __bitwise osd_cdb_offset;
    +
    +enum {
    + OSD_OFFSET_UNUSED = 0xFFFFFFFF,
    + OSD_OFFSET_MAX_BITS = 28,
    +
    + OSDv1_OFFSET_MIN_SHIFT = 8,
    + OSD_OFFSET_MAX_SHIFT = 16,
    +};
    +
    +/* Return the smallest allowed encoded offset that contains @offset.
    + *
    + * The actual encoded offset returned is @offset + *padding.
    + * (up to max_shift, non-inclusive)
    + */
    +osd_cdb_offset __osd_encode_offset(u64 offset, unsigned *padding,
    + int min_shift, int max_shift);
    +
    +/* Minimum alignment is 256 bytes
    + * Note: Seems from std v1 that exponent can be from 0+8 to 0xE+8 (inclusive)
    + * which is 8 to 23 but IBM code restricts it to 16, so be it.
    + */
    +static inline osd_cdb_offset osd_encode_offset_v1(u64 offset, unsigned *padding)
    +{
    + return __osd_encode_offset(offset, padding,
    + OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
    +}
    +
    +/* osd2r03: 5.2.1 Overview */
    +struct osd_cdb_head {
    + struct scsi_varlen_cdb_hdr varlen_cdb;
    +/*10*/ u8 options;
    + u8 command_specific_options;
    + u8 timestamp_control;
    +/*13*/ u8 reserved1[3];
    +/*16*/ __be64 partition;
    +/*24*/ __be64 object;
    +/*32*/ union { /* V1 vs V2 alignment differences */
    + struct __osdv1_cdb_addr_len {
    +/*32*/ __be32 list_identifier;/* Rarely used */
    +/*36*/ __be64 length;
    +/*44*/ __be64 start_address;
    + } __packed v1;
    + };
    +/*52*/ union { /* selected attributes mode Page/List/Single */
    + struct osd_attributes_page_mode {
    +/*52*/ __be32 get_attr_page;
    +/*56*/ __be32 get_attr_alloc_length;
    +/*60*/ osd_cdb_offset get_attr_offset;
    +
    +/*64*/ __be32 set_attr_page;
    +/*68*/ __be32 set_attr_id;
    +/*72*/ __be32 set_attr_length;
    +/*76*/ osd_cdb_offset set_attr_offset;
    + } __packed attrs_page;
    +
    + struct osd_attributes_list_mode {
    +/*52*/ __be32 get_attr_desc_bytes;
    +/*56*/ osd_cdb_offset get_attr_desc_offset;
    +
    +/*60*/ __be32 get_attr_alloc_length;
    +/*64*/ osd_cdb_offset get_attr_offset;
    +
    +/*68*/ __be32 set_attr_bytes;
    +/*72*/ osd_cdb_offset set_attr_offset;
    + __be32 not_used;
    + } __packed attrs_list;
    +
    + /* osd2r03:5.2.4.2 Set one attribute value using CDB fields */
    + struct osd_attributes_cdb_mode {
    +/*52*/ __be32 set_attr_page;
    +/*56*/ __be32 set_attr_id;
    +/*60*/ __be16 set_attr_len;
    +/*62*/ u8 set_attr_val[80-62];
    + } __packed attrs_cdb;
    +/*52*/ u8 get_set_attributes_parameters[80-52];
    + };
    +} __packed;
    +/*80*/
    +
    +/*160 v1*/
    +struct osd_security_parameters {
    +/*160*/u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
    +/*180*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
    +/*192*/osd_cdb_offset data_in_integrity_check_offset;
    +/*196*/osd_cdb_offset data_out_integrity_check_offset;
    +} __packed;
    +/*200 v1*/
    +
    +struct osdv1_cdb {
    + struct osd_cdb_head h;
    + u8 caps[OSDv1_CAP_LEN];
    + struct osd_security_parameters sec_params;
    +} __packed;
    +
    +struct osd_cdb {
    + union {
    + struct osdv1_cdb v1;
    + u8 buff[OSD_TOTAL_CDB_LEN];
    + };
    +} __packed;
    +
    +static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
    +{
    + return (struct osd_cdb_head *)ocdb->buff;
    +}
    +
    +/* define both version actions
    + * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
    + */
    +#define OSD_ACT___(Name, Num) \
    + OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), \
    + OSDv1_ACT_##Name = __constant_cpu_to_be16(0x8800 + Num),
    +
    +/* V2 only actions */
    +#define OSD_ACT_V2(Name, Num) \
    + OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num),
    +
    +#define OSD_ACT_V1_V2(Name, Num1, Num2) \
    + OSD_ACT_##Name = __constant_cpu_to_be16(Num2), \
    + OSDv1_ACT_##Name = __constant_cpu_to_be16(Num1),
    +
    +enum osd_service_actions {
    + OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00)
    + OSD_ACT___(FORMAT_OSD, 0x01)
    + OSD_ACT___(CREATE, 0x02)
    + OSD_ACT___(LIST, 0x03)
    + OSD_ACT_V2(PUNCH, 0x04)
    + OSD_ACT___(READ, 0x05)
    + OSD_ACT___(WRITE, 0x06)
    + OSD_ACT___(APPEND, 0x07)
    + OSD_ACT___(FLUSH, 0x08)
    + OSD_ACT_V2(CLEAR, 0x09)
    + OSD_ACT___(REMOVE, 0x0A)
    + OSD_ACT___(CREATE_PARTITION, 0x0B)
    + OSD_ACT___(REMOVE_PARTITION, 0x0C)
    + OSD_ACT___(GET_ATTRIBUTES, 0x0E)
    + OSD_ACT___(SET_ATTRIBUTES, 0x0F)
    + OSD_ACT___(CREATE_AND_WRITE, 0x12)
    + OSD_ACT___(CREATE_COLLECTION, 0x15)
    + OSD_ACT___(REMOVE_COLLECTION, 0x16)
    + OSD_ACT___(LIST_COLLECTION, 0x17)
    + OSD_ACT___(SET_KEY, 0x18)
    + OSD_ACT___(SET_MASTER_KEY, 0x19)
    + OSD_ACT___(FLUSH_COLLECTION, 0x1A)
    + OSD_ACT___(FLUSH_PARTITION, 0x1B)
    + OSD_ACT___(FLUSH_OSD, 0x1C)
    +
    + OSD_ACT_V2(QUERY, 0x20)
    + OSD_ACT_V2(REMOVE_MEMBER_OBJECTS, 0x21)
    + OSD_ACT_V2(GET_MEMBER_ATTRIBUTES, 0x22)
    + OSD_ACT_V2(SET_MEMBER_ATTRIBUTES, 0x23)
    + OSD_ACT_V2(READ_MAP, 0x31)
    +
    + OSD_ACT_V1_V2(PERFORM_SCSI_COMMAND, 0x8F7E, 0x8F7C)
    + OSD_ACT_V1_V2(SCSI_TASK_MANAGEMENT, 0x8F7F, 0x8F7D)
    + /* 0x8F80 to 0x8FFF are Vendor specific */
    +};
    +
    +/* osd2r03: 7.1.3.2 List entry format for retrieving attributes */
    +struct osd_attributes_list_attrid {
    + __be32 page;
    + __be32 attr_id;
    +} __packed;
    +
    +/*
    + * osd2r03: 7.1.3.3 List entry format for retrieved attributes and
    + * for setting attributes
    + */
    +struct osd_attributes_list_element {
    + __be32 page;
    + __be32 attr_id;
    + __be16 attr_bytes;
    + u8 attr_val[0];
    +} __packed;
    +
    +enum {
    + OSDv1_ATTRIBUTES_ELEM_ALIGN = 1,
    +};
    +
    +enum {
    + OSD_ATTR_LIST_ALL_PAGES = 0xFFFFFFFF,
    + OSD_ATTR_LIST_ALL_IN_PAGE = 0xFFFFFFFF,
    +};
    +
    +static inline unsigned osdv1_attr_list_elem_size(unsigned len)
    +{
    + return ALIGN(len + sizeof(struct osd_attributes_list_element),
    + OSDv1_ATTRIBUTES_ELEM_ALIGN);
    +}
    +
    +/*
    + * osd2r03: 7.1.3 OSD attributes lists (Table 184) — List type values
    + */
    +enum osd_attr_list_types {
    + OSD_ATTR_LIST_GET = 0x1, /* descriptors only */
    + OSD_ATTR_LIST_SET_RETRIEVE = 0x9, /*descriptors/values variable-length*/
    + OSD_V2_ATTR_LIST_MULTIPLE = 0xE, /* ver2, Multiple Objects lists*/
    + OSD_V1_ATTR_LIST_CREATE_MULTIPLE = 0xF,/*ver1, used by create_multple*/
    +};
    +
    +/* osd2r03: 7.1.3.4 Multi-object retrieved attributes format */
    +struct osd_attributes_list_multi_header {
    + __be64 object_id;
    + u8 object_type; /* object_type enum below */
    + u8 reserved[5];
    + __be16 list_bytes;
    + /* followed by struct osd_attributes_list_element's */
    +};
    +
    +struct osdv1_attributes_list_header {
    + u8 type; /* low 4-bit only */
    + u8 pad;
    + __be16 list_bytes; /* Initiator shall set to Zero. Only set by target */
    + /*
    + * type=9 followed by struct osd_attributes_list_element's
    + * type=E followed by struct osd_attributes_list_multi_header's
    + */
    +} __packed;
    +
    +static inline unsigned osdv1_list_size(struct osdv1_attributes_list_header *h)
    +{
    + return be16_to_cpu(h->list_bytes);
    +}
    +
    +/* (osd-r10 6.13)
    + * osd2r03: 6.15 LIST (Table 79) LIST command parameter data.
    + * for root_lstchg below
    + */
    +enum {
    + OSD_OBJ_ID_LIST_PAR = 0x1, /* V1-only. Not used in V2 */
    + OSD_OBJ_ID_LIST_LSTCHG = 0x2,
    +};
    +
    +/*
    + * osd2r03: 6.15.2 LIST command parameter data
    + * (Also for LIST COLLECTION)
    + */
    +struct osd_obj_id_list {
    + __be64 list_bytes; /* bytes in list excluding list_bytes (-8) */
    + __be64 continuation_id;
    + __be32 list_identifier;
    + u8 pad[3];
    + u8 root_lstchg;
    + __be64 object_ids[0];
    +} __packed;
    +
    +static inline bool osd_is_obj_list_done(struct osd_obj_id_list *list,
    + bool *is_changed)
    +{
    + *is_changed = (0 != (list->root_lstchg & OSD_OBJ_ID_LIST_LSTCHG));
    + return 0 != list->continuation_id;
    +}
    +
    +/*
    + * osd2r03: 4.12.4.5 The ALLDATA security method
    + */
    +struct osd_data_out_integrity_info {
    + __be64 data_bytes;
    + __be64 set_attributes_bytes;
    + __be64 get_attributes_bytes;
    + __be64 integrity_check_value;
    +} __packed;
    +
    +struct osd_data_in_integrity_info {
    + __be64 data_bytes;
    + __be64 retrieved_attributes_bytes;
    + __be64 integrity_check_value;
    +} __packed;
    +
    +struct osd_timestamp {
    + u8 time[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */
    +} __packed;
    +/* FIXME: define helper functions to convert to/from osd time format */
    +
    +/*
    + * Capability & Security definitions
    + * osd2r03: 4.11.2.2 Capability format
    + * osd2r03: 5.2.8 Security parameters
    + */
    +
    +struct osd_key_identifier {
    + u8 id[7]; /* if you know why 7 please email bharrosh@panasas.com */
    +} __packed;
    +
    +/* for osd_capability.format */
    +enum {
    + OSD_SEC_CAP_FORMAT_NO_CAPS = 0,
    + OSD_SEC_CAP_FORMAT_VER1 = 1,
    + OSD_SEC_CAP_FORMAT_VER2 = 2,
    +};
    +
    +/* security_method */
    +enum {
    + OSD_SEC_NOSEC = 0,
    + OSD_SEC_CAPKEY = 1,
    + OSD_SEC_CMDRSP = 2,
    + OSD_SEC_ALLDATA = 3,
    +};
    +
    +enum object_type {
    + OSD_SEC_OBJ_ROOT = 0x1,
    + OSD_SEC_OBJ_PARTITION = 0x2,
    + OSD_SEC_OBJ_COLLECTION = 0x40,
    + OSD_SEC_OBJ_USER = 0x80,
    +};
    +
    +enum osd_capability_bit_masks {
    + OSD_SEC_CAP_APPEND = (1 << 0),
    + OSD_SEC_CAP_OBJ_MGMT = (1 << 1),
    + OSD_SEC_CAP_REMOVE = (1 << 2),
    + OSD_SEC_CAP_CREATE = (1 << 3),
    + OSD_SEC_CAP_SET_ATTR = (1 << 4),
    + OSD_SEC_CAP_GET_ATTR = (1 << 5),
    + OSD_SEC_CAP_WRITE = (1 << 6),
    + OSD_SEC_CAP_READ = (1 << 7),
    +
    + OSD_SEC_CAP_NONE1 = (1 << 8),
    + OSD_SEC_CAP_NONE2 = (1 << 9),
    + OSD_SEC_CAP_NONE3 = (1 << 10),
    + OSD_SEC_CAP_QUERY = (1 << 11), /*v2 only*/
    + OSD_SEC_CAP_M_OBJECT = (1 << 12), /*v2 only*/
    + OSD_SEC_CAP_POL_SEC = (1 << 13),
    + OSD_SEC_CAP_GLOBAL = (1 << 14),
    + OSD_SEC_CAP_DEV_MGMT = (1 << 15),
    +};
    +
    +/* for object_descriptor_type (hi nibble used) */
    +enum {
    + OSD_SEC_OBJ_DESC_NONE = 0, /* Not allowed */
    + OSD_SEC_OBJ_DESC_OBJ = 1 << 4, /* v1: also collection */
    + OSD_SEC_OBJ_DESC_PAR = 2 << 4, /* also root */
    + OSD_SEC_OBJ_DESC_COL = 3 << 4, /* v2 only */
    +};
    +
    +/* (osd-r10:4.9.2.2)
    + * osd2r03:4.11.2.2 Capability format
    + */
    +struct osd_capability_head {
    + u8 format; /* low nibble */
    + u8 integrity_algorithm__key_version; /* MAKE_BYTE(integ_alg, key_ver) */
    + u8 security_method;
    + u8 reserved1;
    +/*04*/ struct osd_timestamp expiration_time;
    +/*10*/ u8 audit[30-10];
    +/*30*/ u8 discriminator[42-30];
    +/*42*/ struct osd_timestamp object_created_time;
    +/*48*/ u8 object_type;
    + u8 permissions_bit_mask[54-49];
    +/*54*/ u8 reserved2;
    +/*55*/ u8 object_descriptor_type; /* high nibble */
    +} __packed;
    +
    +/*56 v1*/
    +struct osdv1_cap_object_descriptor {
    + union {
    + struct {
    +/*56*/ __be32 policy_access_tag;
    +/*60*/ __be64 allowed_partition_id;
    +/*68*/ __be64 allowed_object_id;
    +/*76*/ __be32 reserved;
    + } __packed obj_desc;
    +
    + u8 object_descriptor[80-56];/*24*/
    + };
    +} __packed;
    +/*80 v1*/
    +
    +struct osd_capability {
    + struct osd_capability_head h;
    + struct osdv1_cap_object_descriptor od;
    +} __packed;
    +
    +/**
    + * osd_sec_set_caps - set cap-bits into the capabilities header
    + *
    + * @cap: The osd_capability_head to set cap bits to.
    + * @bit_mask: Use an ORed list of enum osd_capability_bit_masks values
    + *
    + * permissions_bit_mask is unaligned use below to set into caps
    + * in a version independent way
    + */
    +static inline void osd_sec_set_caps(struct osd_capability_head *cap,
    + u16 bit_mask)
    +{
    + /*
    + *Note: The bits above are defined LE order this is because this way
    + * they can grow in the future to more then 16, and still retain
    + * there constant values.
    + */
    + put_unaligned_le16(bit_mask, &cap->permissions_bit_mask);
    +}
    +
    +#endif /* ndef __OSD_PROTOCOL_H__ */
    diff --git a/include/scsi/osd_sec.h b/include/scsi/osd_sec.h
    new file mode 100644
    index 0000000..4c09fee
    --- /dev/null
    +++ b/include/scsi/osd_sec.h
    @@ -0,0 +1,45 @@
    +/*
    + * osd_sec.h - OSD security manager API
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + */
    +#ifndef __OSD_SEC_H__
    +#define __OSD_SEC_H__
    +
    +#include "osd_protocol.h"
    +#include "osd_types.h"
    +
    +/*
    + * Contains types and constants of osd capabilities and security
    + * encoding/decoding.
    + * API is trying to keep security abstract so initiator of an object
    + * based pNFS client knows as little as possible about security and
    + * capabilities. It is the Server's osd-initiator place to know more.
    + * Also can be used by osd-target.
    + */
    +void osd_sec_encode_caps(void *caps, ...);/* NI */
    +void osd_sec_init_nosec_doall_caps(void *caps,
    + const struct osd_obj_id *obj, bool is_collection, const bool is_v1);
    +
    +bool osd_is_sec_alldata(struct osd_security_parameters *sec_params);
    +
    +/* Conditionally sign the CDB according to security setting in ocdb
    + * with cap_key */
    +void osd_sec_sign_cdb(struct osd_cdb *ocdb, const u8 *cap_key);
    +
    +/* Unconditionally sign the BIO data with cap_key.
    + * Check for osd_is_sec_alldata() was done prior to calling this. */
    +void osd_sec_sign_data(void *data_integ, struct bio *bio, const u8 *cap_key);
    +
    +/* Version independent copy of caps into the cdb */
    +void osd_set_caps(struct osd_cdb *cdb, const void *caps);
    +
    +#endif /* ndef __OSD_SEC_H__ */
    diff --git a/include/scsi/osd_types.h b/include/scsi/osd_types.h
    new file mode 100644
    index 0000000..ea5372d
    --- /dev/null
    +++ b/include/scsi/osd_types.h
    @@ -0,0 +1,40 @@
    +/*
    + * osd_types.h - Types and constants which are not part of the protocol.
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + * Contains types and constants that are implementation specific and are
    + * used by more than one part of the osd library.
    + * (Eg initiator/target/security_manager/...)
    + */
    +#ifndef __OSD_TYPES_H__
    +#define __OSD_TYPES_H__
    +
    +struct osd_systemid {
    + u8 data[OSD_SYSTEMID_LEN];
    +};
    +
    +typedef u64 __bitwise osd_id;
    +
    +struct osd_obj_id {
    + osd_id partition;
    + osd_id id;
    +};
    +
    +static const struct __weak osd_obj_id osd_root_object = {0, 0};
    +
    +struct osd_attr {
    + u32 page;
    + u32 attr_id;
    + u16 len; /* byte count of operand */
    + void *val_ptr; /* in network order */
    +};
    +
    +#endif /* ndef __OSD_TYPES_H__ */
    --
    1.6.0.1


    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  3. Re: [PATCHSET 00/18] open-osd: OSD Initiator library for Linux

    Andrew Morton wrote:
    > On Tue, 04 Nov 2008 18:09:31 +0200
    > Boaz Harrosh wrote:
    >
    >> Please consider for inclusion, an in-kernel OSD initiator
    >> library. Its main users are planned to be various OSD based file
    >> systems and the pNFS-Objects Layout Driver. (To be submitted soon)
    >>
    >> To try out and run the library please visit
    >> http://open-osd.org and follow the instructions there.
    >>
    >> The submitted patchset is also available via git at:
    >> git://git.open-osd.org/linux-open-osd.git osd
    >> http://git.open-osd.org/gitweb.cgi?p...shortlog;h=osd
    >>
    >> Or a compact out-of-tree repository that includes sources
    >> and some extras:
    >> git://git.open-osd.org/open-osd.git master
    >> http://git.open-osd.org/gitweb.cgi?p....git;a=summary
    >>
    >> ...
    >>
    >> We would like this to sit in -mm tree for a while to make sure it is compilable
    >> on all platform.

    >
    > The best way to do that is to include your git tree in linux-next. If
    > this code has a probably-will-be-merged-in-2.6.29 status then please
    > prepare a branch for Stephen to include in the linux-next lineup.
    >


    Hi Stephen and James

    I have prepared a branch for linux-next based on today's Linus tree
    It is here:
    git://git.open-osd.org/linux-open-osd.git linux-next
    This is if it's OK with James, as these bits are his responsibility.
    They need only sit in linux-next for a couple of weeks to get some wider
    compilation exposure. Other then that they are totally new code and
    are safe. Eventually they should be included into Linux-next through
    scsi-misc-2.6.

    I have only posted "ver 2" updates to a couple of patches that had
    comments by people but more patches changed. Mainly:
    - rename of scsi_dev => scsi_device
    - missing static keyword
    - Kbuild fixes and comments by Sam Ravnborg
    - small typos found on the way

    The new patchset can be reviewed at:
    git://git.open-osd.org/linux-open-osd.git linux-next
    http://git.open-osd.org/gitweb.cgi?p...g;h=linux-next

    or Based on current scsi-misc-2.6:
    git://git.open-osd.org/linux-open-osd.git osd
    http://git.open-osd.org/gitweb.cgi?p...shortlog;h=osd

    I did not want to spam the mailing-list with somewhat same patches.
    I will post them, if any one needs me to.

    Thanks everyone for your help
    Boaz
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  4. [PATCH 04/18 ver2] libosd: OSDv1 preliminary implementation


    Implementation of the most basic OSD functionality and
    infrastructure. Mainly Format, Create/Remove Partition,
    Create/Remove Object, and read/write.

    - Add Makefile and Kbuild to compile libosd.ko
    - osd_initiator.c Implementation file for osd_initiator.h
    and osd_sec.h APIs
    - osd_debug.h - Some kprintf macro definitions

    Signed-off-by: Boaz Harrosh
    Reviewed-by: Benny Halevy
    ---
    drivers/scsi/osd/Kbuild | 26 +++
    drivers/scsi/osd/Makefile | 37 +++
    drivers/scsi/osd/osd_debug.h | 27 +++
    drivers/scsi/osd/osd_initiator.c | 448 ++++++++++++++++++++++++++++++++++++++
    4 files changed, 538 insertions(+), 0 deletions(-)
    create mode 100644 drivers/scsi/osd/Kbuild
    create mode 100755 drivers/scsi/osd/Makefile
    create mode 100644 drivers/scsi/osd/osd_debug.h
    create mode 100644 drivers/scsi/osd/osd_initiator.c

    diff --git a/drivers/scsi/osd/Kbuild b/drivers/scsi/osd/Kbuild
    new file mode 100644
    index 0000000..b6328e6
    --- /dev/null
    +++ b/drivers/scsi/osd/Kbuild
    @@ -0,0 +1,26 @@
    +#
    +# Kbuild for the OSD modules
    +#
    +# Copyright (C) 2008 Panasas Inc. All rights reserved.
    +#
    +# Authors:
    +# Boaz Harrosh
    +# Benny Halevy
    +#
    +# This program is free software; you can redistribute it and/or modify
    +# it under the terms of the GNU General Public License version 2
    +#
    +
    +ifneq ($(OSD_INC),)
    +# we are built out-of-tree Kconfigure everything as on
    +
    +CONFIG_SCSI_OSD_INITIATOR=m
    +ccflags-y += -DCONFIG_SCSI_OSD_INITIATOR -DCONFIG_SCSI_OSD_INITIATOR_MODULE
    +
    +ccflags-y += -I$(OSD_INC)
    +# ccflags-y += -DCONFIG_SCSI_OSD_DEBUG
    +endif
    +
    +# libosd.ko - osd-initiator library
    +libosd-y := osd_initiator.o
    +obj-$(CONFIG_SCSI_OSD_INITIATOR) += libosd.o
    diff --git a/drivers/scsi/osd/Makefile b/drivers/scsi/osd/Makefile
    new file mode 100755
    index 0000000..d905344
    --- /dev/null
    +++ b/drivers/scsi/osd/Makefile
    @@ -0,0 +1,37 @@
    +#
    +# Makefile for the OSD modules (out of tree)
    +#
    +# Copyright (C) 2008 Panasas Inc. All rights reserved.
    +#
    +# Authors:
    +# Boaz Harrosh
    +# Benny Halevy
    +#
    +# This program is free software; you can redistribute it and/or modify
    +# it under the terms of the GNU General Public License version 2
    +#
    +# This Makefile is used to call the kernel Makefile in case of an out-of-tree
    +# build.
    +# $KSRC should point to a Kernel source tree otherwise host's default is
    +# used. (eg. /lib/modules/`uname -r`/build)
    +
    +# include path for out-of-tree Headers
    +OSD_INC ?= `pwd`/../../../include
    +
    +# allow users to override these
    +# e.g. to compile for a kernel that you aren't currently running
    +KSRC ?= /lib/modules/$(shell uname -r)/build
    +KBUILD_OUTPUT ?=
    +ARCH ?=
    +V ?= 0
    +
    +# this is the basic Kbuild out-of-tree invocation, with the M= option
    +KBUILD_BASE = +$(MAKE) -C $(KSRC) M=`pwd` KBUILD_OUTPUT=$(KBUILD_OUTPUT) ARCH=$(ARCH) V=$(V)
    +
    +all: libosd
    +
    +libosd: ;
    + $(KBUILD_BASE) OSD_INC=$(OSD_INC) modules
    +
    +clean:
    + $(KBUILD_BASE) clean
    diff --git a/drivers/scsi/osd/osd_debug.h b/drivers/scsi/osd/osd_debug.h
    new file mode 100644
    index 0000000..0bc65fa
    --- /dev/null
    +++ b/drivers/scsi/osd/osd_debug.h
    @@ -0,0 +1,27 @@
    +/*
    + * osd_debug.h - Some kprintf macros
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + */
    +#ifndef __OSD_DEBUG_H__
    +#define __OSD_DEBUG_H__
    +
    +#define OSD_ERR(fmt, a...) printk(KERN_ERR "osd: " fmt, ##a)
    +#define OSD_INFO(fmt, a...) printk(KERN_NOTICE "osd: " fmt, ##a)
    +
    +#ifdef CONFIG_SCSI_OSD_DEBUG
    +#define OSD_DEBUG(fmt, a...) \
    + printk(KERN_NOTICE "osd @%s:%d: " fmt, __func__, __LINE__, ##a)
    +#else
    +#define OSD_DEBUG(fmt, a...) do {} while (0)
    +#endif
    +
    +#endif /* ndef __OSD_DEBUG_H__ */
    diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
    new file mode 100644
    index 0000000..63b8a91
    --- /dev/null
    +++ b/drivers/scsi/osd/osd_initiator.c
    @@ -0,0 +1,448 @@
    +/*
    + * osd_initiator - Main body of the osd initiator library.
    + *
    + * Note: The file does not contain the advanced security functionality which
    + * is only needed by the security_manager's initiators.
    + *
    + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    + *
    + * Authors:
    + * Boaz Harrosh
    + * Benny Halevy
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License version 2
    + *
    + * Redistribution and use in source and binary forms, with or without
    + * modification, are permitted provided that the following conditions
    + * are met:
    + *
    + * 1. Redistributions of source code must retain the above copyright
    + * notice, this list of conditions and the following disclaimer.
    + * 2. Redistributions in binary form must reproduce the above copyright
    + * notice, this list of conditions and the following disclaimer in the
    + * documentation and/or other materials provided with the distribution.
    + * 3. Neither the name of the Panasas company nor the names of its
    + * contributors may be used to endorse or promote products derived
    + * from this software without specific prior written permission.
    + *
    + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
    + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
    + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    + */
    +
    +#include
    +#include
    +#include
    +
    +#include "osd_debug.h"
    +
    +enum { OSD_REQ_RETRIES = 1 };
    +
    +MODULE_AUTHOR("Boaz Harrosh ");
    +MODULE_DESCRIPTION("open-osd initiator library libosd.ko");
    +MODULE_LICENSE("GPL");
    +
    +static inline void build_test(void)
    +{
    + /* structures were not packed */
    + BUILD_BUG_ON(sizeof(struct osd_capability) != OSD_CAP_LEN);
    + BUILD_BUG_ON(sizeof(struct osdv1_cdb) != OSDv1_TOTAL_CDB_LEN);
    +}
    +
    +static unsigned _osd_req_cdb_len(struct osd_request *or)
    +{
    + return OSDv1_TOTAL_CDB_LEN;
    +}
    +
    +void osd_dev_init(struct osd_dev *osdd, struct scsi_device *scsi_device)
    +{
    + memset(osdd, 0, sizeof(*osdd));
    + osdd->scsi_device = scsi_device;
    + osdd->def_timeout = BLK_DEFAULT_SG_TIMEOUT;
    + /* TODO: Allocate pools for osd_request attributes ... */
    +}
    +EXPORT_SYMBOL(osd_dev_init);
    +
    +void osd_dev_fini(struct osd_dev *osdd)
    +{
    + /* TODO: De-allocate pools */
    +
    + osdd->scsi_device = NULL;
    +}
    +EXPORT_SYMBOL(osd_dev_fini);
    +
    +static struct osd_request *_osd_request_alloc(gfp_t gfp)
    +{
    + struct osd_request *or;
    +
    + /* TODO: Use mempool with one saved request */
    + or = kzalloc(sizeof(*or), gfp);
    + return or;
    +}
    +
    +static void _osd_request_free(struct osd_request *or)
    +{
    + kfree(or);
    +}
    +
    +struct osd_request *osd_start_request(struct osd_dev *dev, gfp_t gfp)
    +{
    + struct osd_request *or;
    +
    + or = _osd_request_alloc(gfp);
    + if (!or)
    + return NULL;
    +
    + or->osd_dev = dev;
    + or->alloc_flags = gfp;
    + or->timeout = dev->def_timeout;
    + or->retries = OSD_REQ_RETRIES;
    +
    + return or;
    +}
    +EXPORT_SYMBOL(osd_start_request);
    +
    +/*
    + * If osd_finalize_request() was called but the request was not executed through
    + * the block layer, then we must release BIOs.
    + */
    +static void _abort_unexecuted_bios(struct request *rq)
    +{
    + struct bio *bio;
    +
    + while ((bio = rq->bio) != NULL) {
    + rq->bio = bio->bi_next;
    + bio_endio(bio, 0);
    + }
    +}
    +
    +void osd_end_request(struct osd_request *or)
    +{
    + struct request *rq = or->request;
    +
    + if (rq) {
    + if (rq->next_rq) {
    + _abort_unexecuted_bios(rq->next_rq);
    + blk_put_request(rq->next_rq);
    + }
    +
    + _abort_unexecuted_bios(rq);
    + blk_put_request(rq);
    + }
    + _osd_request_free(or);
    +}
    +EXPORT_SYMBOL(osd_end_request);
    +
    +int osd_execute_request(struct osd_request *or)
    +{
    + return blk_execute_rq(or->request->q, NULL, or->request, 0);
    +}
    +EXPORT_SYMBOL(osd_execute_request);
    +
    +static void osd_request_async_done(struct request *req, int error)
    +{
    + struct osd_request *or = req->end_io_data;
    +
    + or->async_error = error;
    +
    + if (error)
    + OSD_DEBUG("osd_request_async_done error recieved %d\n", error);
    +
    + if (or->async_done)
    + or->async_done(or, or->async_private);
    + else
    + osd_end_request(or);
    +}
    +
    +int osd_execute_request_async(struct osd_request *or,
    + osd_req_done_fn *done, void *private)
    +{
    + or->request->end_io_data = or;
    + or->async_private = private;
    + or->async_done = done;
    +
    + blk_execute_rq_nowait(or->request->q, NULL, or->request, 0,
    + osd_request_async_done);
    + return 0;
    +}
    +EXPORT_SYMBOL(osd_execute_request_async);
    +
    +/*
    + * Common to all OSD commands
    + */
    +
    +static void _osdv1_req_encode_common(struct osd_request *or,
    + __be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
    +{
    + struct osdv1_cdb *ocdb = &or->cdb.v1;
    +
    + /*
    + * For speed, the commands
    + * OSD_ACT_PERFORM_SCSI_COMMAND , V1 0x8F7E, V2 0x8F7C
    + * OSD_ACT_SCSI_TASK_MANAGEMENT , V1 0x8F7F, V2 0x8F7D
    + * are not supported here. Should pass zero and set after the call
    + */
    + act &= __constant_cpu_to_be16(~0x0080); /* V1 action code */
    +
    + OSD_DEBUG("OSDv1 execute opcode 0x%x\n", be16_to_cpu(act));
    +
    + ocdb->h.varlen_cdb.opcode = VARIABLE_LENGTH_CMD;
    + ocdb->h.varlen_cdb.additional_cdb_length = OSD_ADDITIONAL_CDB_LENGTH;
    + ocdb->h.varlen_cdb.service_action = act;
    +
    + ocdb->h.partition = cpu_to_be64(obj->partition);
    + ocdb->h.object = cpu_to_be64(obj->id);
    + ocdb->h.v1.length = cpu_to_be64(len);
    + ocdb->h.v1.start_address = cpu_to_be64(offset);
    +}
    +
    +static void _osd_req_encode_common(struct osd_request *or,
    + __be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
    +{
    + _osdv1_req_encode_common(or, act, obj, offset, len);
    +}
    +
    +/*
    + * Device commands
    + */
    +void osd_req_format(struct osd_request *or, u64 tot_capacity)
    +{
    + _osd_req_encode_common(or, OSD_ACT_FORMAT_OSD, &osd_root_object, 0,
    + tot_capacity);
    +}
    +EXPORT_SYMBOL(osd_req_format);
    +
    +/*
    + * Partition commands
    + */
    +static void _osd_req_encode_partition(struct osd_request *or,
    + __be16 act, osd_id partition)
    +{
    + struct osd_obj_id par = {
    + .partition = partition,
    + .id = 0,
    + };
    +
    + _osd_req_encode_common(or, act, &par, 0, 0);
    +}
    +
    +void osd_req_create_partition(struct osd_request *or, osd_id partition)
    +{
    + _osd_req_encode_partition(or, OSD_ACT_CREATE_PARTITION, partition);
    +}
    +EXPORT_SYMBOL(osd_req_create_partition);
    +
    +void osd_req_remove_partition(struct osd_request *or, osd_id partition)
    +{
    + _osd_req_encode_partition(or, OSD_ACT_REMOVE_PARTITION, partition);
    +}
    +EXPORT_SYMBOL(osd_req_remove_partition);
    +
    +/*
    + * Object commands
    + */
    +void osd_req_create_object(struct osd_request *or, struct osd_obj_id *obj)
    +{
    + _osd_req_encode_common(or, OSD_ACT_CREATE, obj, 0, 0);
    +}
    +EXPORT_SYMBOL(osd_req_create_object);
    +
    +void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *obj)
    +{
    + _osd_req_encode_common(or, OSD_ACT_REMOVE, obj, 0, 0);
    +}
    +EXPORT_SYMBOL(osd_req_remove_object);
    +
    +void osd_req_write(struct osd_request *or,
    + const struct osd_obj_id *obj, struct bio *bio, u64 offset)
    +{
    + _osd_req_encode_common(or, OSD_ACT_WRITE, obj, offset, bio->bi_size);
    + WARN_ON(or->out.bio || or->out.total_bytes);
    + bio->bi_rw |= (1 << BIO_RW);
    + or->out.bio = bio;
    + or->out.total_bytes = bio->bi_size;
    +}
    +EXPORT_SYMBOL(osd_req_write);
    +
    +void osd_req_read(struct osd_request *or,
    + const struct osd_obj_id *obj, struct bio *bio, u64 offset)
    +{
    + _osd_req_encode_common(or, OSD_ACT_READ, obj, offset, bio->bi_size);
    + WARN_ON(or->in.bio || or->in.total_bytes);
    + bio->bi_rw &= ~(1 << BIO_RW);
    + or->in.bio = bio;
    + or->in.total_bytes = bio->bi_size;
    +}
    +EXPORT_SYMBOL(osd_req_read);
    +
    +/*
    + * osd_finalize_request and helpers
    + */
    +
    +static int _init_blk_request(struct osd_request *or,
    + bool has_in, bool has_out)
    +{
    + gfp_t flags = or->alloc_flags;
    + struct scsi_device *scsi_device = or->osd_dev->scsi_device;
    + struct request_queue *q = scsi_device->request_queue;
    + struct request *req;
    + int ret = -ENOMEM;
    +
    + req = blk_get_request(q, has_out, flags);
    + if (!req)
    + goto out;
    +
    + or->request = req;
    + req->cmd_type = REQ_TYPE_BLOCK_PC;
    + req->timeout = or->timeout;
    + req->retries = or->retries;
    + req->sense = or->sense;
    + req->sense_len = 0;
    +
    + if (has_out) {
    + or->out.req = req;
    + if (has_in) {
    + /* allocate bidi request */
    + req = blk_get_request(q, READ, flags);
    + if (!req) {
    + OSD_DEBUG("blk_get_request for bidi failed\n");
    + goto out;
    + }
    + req->cmd_type = REQ_TYPE_BLOCK_PC;
    + or->in.req = or->request->next_rq = req;
    + }
    + } else if (has_in)
    + or->in.req = req;
    +
    + ret = 0;
    +out:
    + OSD_DEBUG("or=%p has_in=%d has_out=%d => %d, %p\n",
    + or, has_in, has_out, ret, or->request);
    + return ret;
    +}
    +
    +int osd_finalize_request(struct osd_request *or,
    + u8 options, const void *cap, const u8 *cap_key)
    +{
    + struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
    + bool has_in, has_out;
    + int ret;
    +
    + if (options & OSD_REQ_FUA)
    + cdbh->options |= OSD_CDB_FUA;
    +
    + if (options & OSD_REQ_DPO)
    + cdbh->options |= OSD_CDB_DPO;
    +
    + if (options & OSD_REQ_BYPASS_TIMESTAMPS)
    + cdbh->timestamp_control = OSD_CDB_BYPASS_TIMESTAMPS;
    +
    + osd_set_caps(&or->cdb, cap);
    +
    + has_in = or->in.bio || or->get_attr.total_bytes;
    + has_out = or->out.bio || or->set_attr.total_bytes ||
    + or->enc_get_attr.total_bytes;
    +
    + ret = _init_blk_request(or, has_in, has_out);
    + if (ret) {
    + OSD_DEBUG("_init_blk_request failed\n");
    + return ret;
    + }
    +
    + if (or->out.bio) {
    + ret = blk_rq_append_bio(or->request->q, or->out.req,
    + or->out.bio);
    + if (ret) {
    + OSD_DEBUG("blk_rq_append_bio out failed\n");
    + return ret;
    + }
    + OSD_DEBUG("out bytes=%llu (bytes_req=%u)\n",
    + or->out.total_bytes, or->out.req->data_len);
    + }
    + if (or->in.bio) {
    + ret = blk_rq_append_bio(or->request->q, or->in.req, or->in.bio);
    + if (ret) {
    + OSD_DEBUG("blk_rq_append_bio in failed\n");
    + return ret;
    + }
    + OSD_DEBUG("in bytes=%llu (bytes_req=%u)\n",
    + or->in.total_bytes, or->in.req->data_len);
    + }
    +
    + if (!or->attributes_mode)
    + or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
    + cdbh->command_specific_options |= or->attributes_mode;
    +
    + or->request->cmd = or->cdb.buff;
    + or->request->cmd_len = _osd_req_cdb_len(or);
    +
    + return 0;
    +}
    +EXPORT_SYMBOL(osd_finalize_request);
    +
    +/*
    + * Implementation of osd_sec.h API
    + * TODO: Move to a separate osd_sec.c file at a later stage.
    + */
    +
    +enum { OSD_SEC_CAP_V1_ALL_CAPS =
    + OSD_SEC_CAP_APPEND | OSD_SEC_CAP_OBJ_MGMT | OSD_SEC_CAP_REMOVE |
    + OSD_SEC_CAP_CREATE | OSD_SEC_CAP_SET_ATTR | OSD_SEC_CAP_GET_ATTR |
    + OSD_SEC_CAP_WRITE | OSD_SEC_CAP_READ | OSD_SEC_CAP_POL_SEC |
    + OSD_SEC_CAP_GLOBAL | OSD_SEC_CAP_DEV_MGMT
    +};
    +
    +void osd_sec_init_nosec_doall_caps(void *caps,
    + const struct osd_obj_id *obj, bool is_collection, const bool is_v1)
    +{
    + struct osd_capability *cap = caps;
    + u8 type;
    + u8 descriptor_type;
    +
    + if (likely(obj->id)) {
    + if (unlikely(is_collection)) {
    + type = OSD_SEC_OBJ_COLLECTION;
    + descriptor_type = is_v1 ? OSD_SEC_OBJ_DESC_OBJ :
    + OSD_SEC_OBJ_DESC_COL;
    + } else {
    + type = OSD_SEC_OBJ_USER;
    + descriptor_type = OSD_SEC_OBJ_DESC_OBJ;
    + }
    + WARN_ON(!obj->partition);
    + } else {
    + type = obj->partition ? OSD_SEC_OBJ_PARTITION :
    + OSD_SEC_OBJ_ROOT;
    + descriptor_type = OSD_SEC_OBJ_DESC_PAR;
    + }
    +
    + memset(cap, 0, sizeof(*cap));
    +
    + cap->h.format = OSD_SEC_CAP_FORMAT_VER1;
    + cap->h.integrity_algorithm__key_version = 0; /* MAKE_BYTE(0, 0); */
    + cap->h.security_method = OSD_SEC_NOSEC;
    +/* cap->expiration_time;
    + cap->AUDIT[30-10];
    + cap->discriminator[42-30];
    + cap->object_created_time; */
    + cap->h.object_type = type;
    + osd_sec_set_caps(&cap->h, OSD_SEC_CAP_V1_ALL_CAPS);
    + cap->h.object_descriptor_type = descriptor_type;
    + cap->od.obj_desc.policy_access_tag = 0;
    + cap->od.obj_desc.allowed_partition_id = cpu_to_be64(obj->partition);
    + cap->od.obj_desc.allowed_object_id = cpu_to_be64(obj->id);
    +}
    +EXPORT_SYMBOL(osd_sec_init_nosec_doall_caps);
    +
    +void osd_set_caps(struct osd_cdb *cdb, const void *caps)
    +{
    + memcpy(&cdb->v1.caps, caps, OSDv1_CAP_LEN);
    +}
    --
    1.6.0.1


    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  5. Re: [PATCH 03/18 ver2] libosd: OSDv1 Headers

    On Sun, 9 November 2008 16:52:36 +0200, Boaz Harrosh wrote:
    >
    > +struct osdv1_cdb {
    > + struct osd_cdb_head h;
    > + u8 caps[OSDv1_CAP_LEN];
    > + struct osd_security_parameters sec_params;
    > +} __packed;


    __packed can result in slow code being generated. But removing the
    attribute can lead to bugs on other architectures. F.e. the size of
    the structure below is different for i386 and x86_64.

    struct foo {
    u64 bar;
    u32 baz;
    };

    My personal solution is to use this little macro and then just follow
    every structure defition with a size check.

    #define SIZE_CHECK(type, size) \
    static inline void check_##type(void) \
    { \
    BUILD_BUG_ON(sizeof(struct type) != (size)); \
    }
    ....
    struct foo {
    u64 bar;
    u32 baz;
    };

    SIZE_CHECK(foo, 12);

    The above would not compile on x86_64 and clearly indicate a missing
    __packed. In other cases the attribute can be removed.

    Jörn

    --
    Invincibility is in oneself, vulnerability is in the opponent.
    -- Sun Tzu
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  6. Re: [PATCHSET 00/18] open-osd: OSD Initiator library for Linux

    Hi Boaz,

    On Sun, 09 Nov 2008 16:58:59 +0200 Boaz Harrosh wrote:
    >
    > I have prepared a branch for linux-next based on today's Linus tree
    > It is here:
    > git://git.open-osd.org/linux-open-osd.git linux-next
    > This is if it's OK with James, as these bits are his responsibility.
    > They need only sit in linux-next for a couple of weeks to get some wider
    > compilation exposure. Other then that they are totally new code and
    > are safe. Eventually they should be included into Linux-next through
    > scsi-misc-2.6.


    I have added that tree to linux-next for today.

    What I say to everyone: commits in that branch must have been posted
    somewhere appropriate, reviewed, unit tested and destined for the next
    merge window. Also, note that my (new) practise is to temporarily drop a
    tree if it causes non-trivial conflicts (especially with Linus' tree), so
    don't be too upset if you get a message from me to that effect.

    --
    Cheers,
    Stephen Rothwell sfr@canb.auug.org.au
    http://www.canb.auug.org.au/~sfr/

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkkXcY8ACgkQjjKRsyhoI8zqiwCgpQfbG13he3 AXK2WXi24Atyg5
    QkQAoLvKrU/ArrvIslvdS3J75rfQm2nX
    =iwiW
    -----END PGP SIGNATURE-----


  7. Re: [osd-dev] [PATCH 04/18] libosd: OSDv1 preliminary implementation

    Boaz Harrosh wrote:
    > Boaz Harrosh wrote:
    >> Sam Ravnborg wrote:
    >>>> +EXPORT_SYMBOL(osd_dev_init);
    >>> kernel-doc comments for all exported funtions / variables.
    >>>

    >> I have some kernel-doc comments of exported functions in the Header
    >> file. I have not yet finished all of them. (Laziness on my part).
    >>
    >> Are kernel-doc comments in headers a big NO-NO. I like it this way,
    >> so when I have to learn a new Library all the information
    >> I need to know is in the header. Also the header is a much better place
    >> when you do programing by shopping, that is you don't know what you need
    >> and you look for what's available.
    >>
    >> Thanks
    >> Boaz

    >
    > Sam please comment if kernel-doc comments are OK in headers


    Hi,

    The de facto standard for kernel-doc comments is at the implementation site,
    which means normally in .c files, except for macros or inline functions.

    Sure you can find some exceptions to that. And there is no hard requirement
    in Documentation/kernel-doc-nano-HOWTO.txt.

    IMO the biggest concern is making sure that the (kernel-doc) comments are
    updated when the function implementation changes (if updates are needed).
    Where would be the best place for this to be more likely to happen?
    Usually at the function implementation, I would say.

    ~Randy


    --
    ~Randy
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  8. Re: [PATCH 03/18 ver2] libosd: OSDv1 Headers

    Jörn Engel wrote:
    > On Sun, 9 November 2008 16:52:36 +0200, Boaz Harrosh wrote:
    >> +struct osdv1_cdb {
    >> + struct osd_cdb_head h;
    >> + u8 caps[OSDv1_CAP_LEN];
    >> + struct osd_security_parameters sec_params;
    >> +} __packed;

    >
    > __packed can result in slow code being generated. But removing the
    > attribute can lead to bugs on other architectures. F.e. the size of
    > the structure below is different for i386 and x86_64.
    >
    > struct foo {
    > u64 bar;
    > u32 baz;
    > };
    >
    > My personal solution is to use this little macro and then just follow
    > every structure defition with a size check.
    >
    > #define SIZE_CHECK(type, size) \
    > static inline void check_##type(void) \
    > { \
    > BUILD_BUG_ON(sizeof(struct type) != (size)); \
    > }
    > ...
    > struct foo {
    > u64 bar;
    > u32 baz;
    > };
    >
    > SIZE_CHECK(foo, 12);
    >
    > The above would not compile on x86_64 and clearly indicate a missing
    > __packed. In other cases the attribute can be removed.
    >
    > Jörn
    >


    Hi Jörn
    Thank you for your comments

    I do have a size check that governs the complete structure it is the first
    code in osd_initiator.c at build_test(). It will catch any discrepancies
    from the protocol.

    I have done some experimentation with __packed both on 32 and 64 bit x86.
    When it does nothing like the above foo in 32bit, then there is no code
    difference with it or with out it, but on 64bit I must have it otherwise
    the structure grows.

    These are all, on-the-wire structures. I must have __packed, otherwise
    I'm at the compiler mercy and that's bad.

    If the assembly - size and offsets - of foo is exactly the same with or
    without the __packed, but the generated code is different then clearly this
    is a compiler bug. I've herd of this myth before, and at least with my
    gcc 4.1.2 there is no such bug. Either the structure gets packed, or there is
    no difference. All the places I have __packed in the code are absolutely must
    be so, stated by the protocol.

    Boaz
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  9. Re: [osd-dev] [PATCH 04/18] libosd: OSDv1 preliminary implementation

    Randy Dunlap wrote:
    > Boaz Harrosh wrote:
    >> Boaz Harrosh wrote:
    >>> Sam Ravnborg wrote:
    >>>>> +EXPORT_SYMBOL(osd_dev_init);
    >>>> kernel-doc comments for all exported funtions / variables.
    >>>>
    >>> I have some kernel-doc comments of exported functions in the Header
    >>> file. I have not yet finished all of them. (Laziness on my part).
    >>>
    >>> Are kernel-doc comments in headers a big NO-NO. I like it this way,
    >>> so when I have to learn a new Library all the information
    >>> I need to know is in the header. Also the header is a much better place
    >>> when you do programing by shopping, that is you don't know what you need
    >>> and you look for what's available.
    >>>
    >>> Thanks
    >>> Boaz

    >> Sam please comment if kernel-doc comments are OK in headers

    >
    > Hi,
    >
    > The de facto standard for kernel-doc comments is at the implementation site,
    > which means normally in .c files, except for macros or inline functions.
    >
    > Sure you can find some exceptions to that. And there is no hard requirement
    > in Documentation/kernel-doc-nano-HOWTO.txt.
    >
    > IMO the biggest concern is making sure that the (kernel-doc) comments are
    > updated when the function implementation changes (if updates are needed).
    > Where would be the best place for this to be more likely to happen?
    > Usually at the function implementation, I would say.
    >
    > ~Randy
    >
    >

    Thanks Randy

    I would like to keep them in the Headers then. This is because I make
    sure that the implementation includes the declaring header, so any miss-matches
    are caught by the compiler.
    And because these are all library routines exported to other modules. The important
    thing is the API you linked with. If the API/parametrization change it must first
    change in the header. The internal implementation is not documented only the external
    black-box functionality is documented in these places.

    I will think about it some more, but for now, if it's OK I would like to keep them
    like submitted. In this particular library they make more sense to me in the header.

    Boaz
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  10. Re: [PATCHSET 00/18] open-osd: OSD Initiator library for Linux

    Stephen Rothwell wrote:
    > Hi Boaz,
    >
    > On Sun, 09 Nov 2008 16:58:59 +0200 Boaz Harrosh wrote:
    >> I have prepared a branch for linux-next based on today's Linus tree
    >> It is here:
    >> git://git.open-osd.org/linux-open-osd.git linux-next
    >> This is if it's OK with James, as these bits are his responsibility.
    >> They need only sit in linux-next for a couple of weeks to get some wider
    >> compilation exposure. Other then that they are totally new code and
    >> are safe. Eventually they should be included into Linux-next through
    >> scsi-misc-2.6.

    >
    > I have added that tree to linux-next for today.
    >
    > What I say to everyone: commits in that branch must have been posted
    > somewhere appropriate, reviewed, unit tested and destined for the next
    > merge window. Also, note that my (new) practise is to temporarily drop a
    > tree if it causes non-trivial conflicts (especially with Linus' tree), so
    > don't be too upset if you get a message from me to that effect.
    >


    Thank you Stephen, very much

    This has proven itself already. I found some warnings on some ARCHs
    concerning printk of u64 types. I have made a sweep and fixed all these
    places and others.
    (same place: git://git.open-osd.org/linux-open-osd.git linux-next)

    If you could keep it for the next round it could be grate. So I can make
    sure I got rid of all the warnings.

    Thanks again
    Boaz
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  11. Re: [PATCHSET 00/18] open-osd: OSD Initiator library for Linux

    Hi Boaz,

    On Mon, 10 Nov 2008 14:52:21 +0200 Boaz Harrosh wrote:
    >
    > This has proven itself already. I found some warnings on some ARCHs
    > concerning printk of u64 types. I have made a sweep and fixed all these
    > places and others.


    Good. That's partly what -next is for (to find the arch dependent
    problems).

    > If you could keep it for the next round it could be grate. So I can make
    > sure I got rid of all the warnings.


    Normally trees stay in linux-next until they are no longer needed
    (usually at least until they have been integrated into Linus' tree) and I
    automatically refetch the trees each day.

    --
    Cheers,
    Stephen Rothwell sfr@canb.auug.org.au
    http://www.canb.auug.org.au/~sfr/

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkkYMUwACgkQjjKRsyhoI8y9LgCcCimEtE9cNQ rHI3suFGiHHsu1
    f9UAoJBZoF4pqROGMRb5Fjibly2B3BFU
    =oOYu
    -----END PGP SIGNATURE-----


  12. Re: [PATCH 03/18 ver2] libosd: OSDv1 Headers

    On Mon, 10 November 2008 10:47:07 +0200, Boaz Harrosh wrote:
    >
    > If the assembly - size and offsets - of foo is exactly the same with or
    > without the __packed, but the generated code is different then clearly this
    > is a compiler bug. I've herd of this myth before, and at least with my
    > gcc 4.1.2 there is no such bug. Either the structure gets packed, or there is
    > no difference. All the places I have __packed in the code are absolutely must
    > be so, stated by the protocol.


    Ok, if current compilers are fine, I won't complain.

    Jörn

    --
    There's nothing better for promoting creativity in a medium than
    making an audience feel "Hmm * I could do better than that!"
    -- Douglas Adams in a slashdot interview
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  13. Re: [PATCH 03/18 ver2] libosd: OSDv1 Headers

    On Sun, 09 Nov 2008 16:52:36 +0200 Boaz Harrosh wrote:

    > Headers only patch.
    >
    > osd_protocol.h
    > Contains a C-fied definition of the T10 OSD standard
    > osd_types.h
    > Contains CPU order common used types
    > osd_initiator.h
    > API definition of the osd_initiator library
    > osd_sec.h
    > Contains High level API for the security manager.
    >
    > [Note that checkpatch spews errors on things that are valid in this context
    > and will not be fixed]
    >
    > Signed-off-by: Boaz Harrosh
    > Reviewed-by: Benny Halevy
    > ---
    > include/scsi/osd_initiator.h | 332 ++++++++++++++++++++++++++++
    > include/scsi/osd_protocol.h | 497 ++++++++++++++++++++++++++++++++++++++++++
    > include/scsi/osd_sec.h | 45 ++++
    > include/scsi/osd_types.h | 40 ++++
    > 4 files changed, 914 insertions(+), 0 deletions(-)
    > create mode 100644 include/scsi/osd_initiator.h
    > create mode 100644 include/scsi/osd_protocol.h
    > create mode 100644 include/scsi/osd_sec.h
    > create mode 100644 include/scsi/osd_types.h
    >
    > diff --git a/include/scsi/osd_initiator.h b/include/scsi/osd_initiator.h
    > new file mode 100644
    > index 0000000..9bab95d
    > --- /dev/null
    > +++ b/include/scsi/osd_initiator.h
    > @@ -0,0 +1,332 @@
    > +/*
    > + * osd_initiator.h - OSD initiator API definition
    > + *
    > + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    > + *
    > + * Authors:
    > + * Boaz Harrosh
    > + * Benny Halevy
    > + *
    > + * This program is free software; you can redistribute it and/or modify
    > + * it under the terms of the GNU General Public License version 2
    > + *
    > + */
    > +#ifndef __OSD_INITIATOR_H__
    > +#define __OSD_INITIATOR_H__
    > +
    > +#include "osd_protocol.h"
    > +#include "osd_types.h"
    > +
    > +#include
    > +
    > +/* Note: "NI" in comments below means "Not Implemented yet" */
    > +
    > +/*
    > + * Object-based Storage Device.
    > + * This object represents an OSD device.
    > + * It is not a full linux device in any way. It is only
    > + * a place to hang resources associated with a Linux
    > + * request Q and some default properties.
    > + */
    > +struct osd_dev {
    > + struct scsi_device *scsi_device;
    > + unsigned def_timeout;
    > +};
    > +
    > +void osd_dev_init(struct osd_dev *, struct scsi_device *scsi_dev);


    Don't mix having parameter names and not having them.
    Preferred is having them.

    > +void osd_dev_fini(struct osd_dev *);
    > +
    > +struct osd_request;
    > +typedef void (osd_req_done_fn)(struct osd_request *, void *);
    > +
    > +struct osd_request {
    > + struct osd_cdb cdb;
    > + struct osd_data_out_integrity_info out_data_integ;
    > + struct osd_data_in_integrity_info in_data_integ;
    > +
    > + struct osd_dev *osd_dev;
    > + struct request *request;
    > +
    > + struct _osd_req_data_segment {
    > + void *buff;
    > + unsigned alloc_size; /* 0 here means not allocated by us */


    Could/would some other code allocate it, or is the "by us" just redundant?

    > + unsigned total_bytes;
    > + } set_attr, enc_get_attr, get_attr;
    > +
    > + struct _osd_io_info {
    > + struct bio *bio;
    > + u64 total_bytes;
    > + struct request *req;
    > + struct _osd_req_data_segment *last_seg;
    > + u8 *pad_buff;
    > + } out, in;
    > +
    > + gfp_t alloc_flags;
    > + unsigned timeout;
    > + unsigned retries;
    > + u8 sense[OSD_MAX_SENSE_LEN];
    > + enum osd_attributes_mode attributes_mode;
    > +
    > + osd_req_done_fn *async_done;
    > + void *async_private;
    > + int async_error;
    > +};
    > +
    > +/**


    Don't start comment blocks with /** when they are not kernel-doc,
    like this one is not.

    > + * How to use the osd library:
    > + *
    > + * osd_start_request
    > + * Allocates a request.
    > + *
    > + * osd_req_*
    > + * Call one of, to encode the desired operation.
    > + *
    > + * osd_add_{get,set}_attr
    > + * Optionally add attributes to the CDB, list or page mode.
    > + *
    > + * osd_finalize_request
    > + * Computes final data out/in offsets and signs the request,
    > + * making it ready for execution.
    > + *
    > + * osd_execute_request
    > + * May be called to execute it through the block layer. Other wise submit
    > + * the associated block request in some other way.
    > + *
    > + * After execution:
    > + * osd_req_decode_sense
    > + * Decodes sense information to verify execution results.
    > + *
    > + * osd_req_decode_get_attr
    > + * Retrieve osd_add_get_attr_list() values if used.
    > + *
    > + * osd_end_request
    > + * Must be called to deallocate the request.
    > + */
    > +
    > +/**
    > + * osd_start_request - Allocate and initialize an osd_request
    > + *
    > + * @osd_dev: OSD device that holds the scsi-device and default values
    > + * that the request is associated with.
    > + * @gfp: The allocation flags to use for request allocation, and all
    > + * subsequent allocations. This will be stored at
    > + * osd_request->alloc_flags, can be changed by user later
    > + *
    > + * Allocate osd_request and initialize all members to the
    > + * default/initial state.
    > + */
    > +struct osd_request *osd_start_request(struct osd_dev *, gfp_t gfp);
    > +
    > +enum osd_req_options {
    > + OSD_REQ_FUA = 0x08, /* Force Unit Access */
    > + OSD_REQ_DPO = 0x10, /* Disable Page Out */
    > +
    > + OSD_REQ_BYPASS_TIMESTAMPS = 0x80,
    > +};
    > +
    > +/**
    > + * osd_finalize_request - Sign request and prepare request for execution
    > + *
    > + * @or: osd_request to prepare
    > + * @options: combination of osd_req_options bit flags or 0.
    > + * @cap A Pointer to an OSD_CAP_LEN bytes buffer that is received from
    > + * The security manager as capabilities for this cdb.
    > + * @cap_key The cryptographic key used to sign the cdb/data. Can be null
    > + * if NOSEC is used.


    Last 2 parameters need a ':' after the @param_name, like the first 2 have.

    > + *
    > + * The actual request and bios are only allocated here, so are the get_attr
    > + * buffers that will receive the returned attributes. Copy's @cap to cdb.
    > + * Sign the cdb/data with @cap_key.
    > + */
    > +int osd_finalize_request(struct osd_request *or,
    > + u8 options, const void *cap, const u8 *cap_key);
    > +
    > +/**
    > + * osd_execute_request - Execute the request synchronously through
    > + * the block-layer


    Function name and short description need to be on one line.

    > + * @or: osd_request to Executed
    > + *
    > + * Calls blk_execute_rq to q the command and waits for completion.
    > + */
    > +int osd_execute_request(struct osd_request *or);
    > +
    > +/**
    > + * osd_execute_request_async - submits the request for execution through
    > + * the block-layer without waitting.


    Ditto.

    > + * @or: - osd_request to Executed
    > + * @done: (Optional) - Called at end of execution
    > + * @private: - Will be passes to @done function


    s/passes/passed/

    > + *
    > + * Calls blk_execute_rq_nowait to q the command. When execution is done
    > + * Optionally calles @done with @private as parameter. or->async_error has the


    s/calles/calls/

    > + * Return code


    and don't start each line with a Capital letter since they are not the
    beginning of sentences. What's with that period ('.') before "or->async_error"
    (which needs a space after "or").


    > + */
    > +int osd_execute_request_async(struct osd_request *or,
    > + osd_req_done_fn *done, void *private);
    > +
    > +/**
    > + * osd_end_request - return osd_request to free store
    > + *
    > + * @or: osd_request to free
    > + *
    > + * Deallocate all osd_request resources (struct req's, BIOs, buffers, etc.)
    > + */
    > +void osd_end_request(struct osd_request *or);
    > +
    > +/*
    > + * CDB Encoding
    > + *
    > + * Note: call only one of the following methods.
    > + */
    > +
    > +/*
    > + * Device commands
    > + */
    > +void osd_req_set_master_seed_xchg(struct osd_request *, ...);/* NI */
    > +void osd_req_set_master_key(struct osd_request *, ...);/* NI */
    > +
    > +void osd_req_format(struct osd_request *, u64 tot_capacity);
    > +
    > +/* list all partitions
    > + * @list header must be initialized to zero on first run.
    > + *
    > + * Call osd_is_obj_list_done() to find if we got the complete list.
    > + */
    > +int osd_req_list_dev_partitions(struct osd_request *,
    > + osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem);
    > +
    > +void osd_req_flush_obsd(struct osd_request *,
    > + enum osd_options_flush_scope_values);
    > +
    > +void osd_req_perform_scsi_command(struct osd_request *,
    > + const u8 *cdb, ...);/* NI */
    > +void osd_req_task_management(struct osd_request *, ...);/* NI */
    > +
    > +/*
    > + * Partition commands
    > + */
    > +void osd_req_create_partition(struct osd_request *, osd_id partition);
    > +void osd_req_remove_partition(struct osd_request *, osd_id partition);
    > +
    > +void osd_req_set_partition_key(struct osd_request *,
    > + osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
    > + u8 seed[OSD_CRYPTO_SEED_SIZE]);/* NI */
    > +
    > +/* list all collections in the partition
    > + * @list header must be init to zero on first run.
    > + *
    > + * Call osd_is_obj_list_done() to find if we got the complete list.
    > + */
    > +int osd_req_list_partition_collections(struct osd_request *,
    > + osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
    > + unsigned nelem);
    > +
    > +/* list all objects in the partition
    > + * @list header must be init to zero on first run.
    > + *
    > + * Call osd_is_obj_list_done() to find if we got the complete list.
    > + */
    > +int osd_req_list_partition_objects(struct osd_request *,
    > + osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
    > + unsigned nelem);
    > +
    > +void osd_req_flush_partition(struct osd_request *,
    > + osd_id partition, enum osd_options_flush_scope_values);
    > +
    > +/*
    > + * Collection commands
    > + */
    > +void osd_req_create_collection(struct osd_request *,
    > + const struct osd_obj_id *);/* NI */
    > +void osd_req_remove_collection(struct osd_request *,
    > + const struct osd_obj_id *);/* NI */
    > +
    > +/* list all objects in the collection */
    > +int osd_req_list_collection_objects(struct osd_request *,
    > + const struct osd_obj_id *, osd_id initial_id,
    > + struct osd_obj_id_list *list, unsigned nelem);
    > +
    > +/* V2 only filtered list of objects in the collection */
    > +void osd_req_query(struct osd_request *, ...);/* NI */
    > +
    > +void osd_req_flush_collection(struct osd_request *,
    > + const struct osd_obj_id *, enum osd_options_flush_scope_values);
    > +
    > +void osd_req_get_member_attrs(struct osd_request *, ...);/* V2-only NI */
    > +void osd_req_set_member_attrs(struct osd_request *, ...);/* V2-only NI */
    > +
    > +/*
    > + * Object commands
    > + */
    > +void osd_req_create_object(struct osd_request *, struct osd_obj_id *);
    > +void osd_req_remove_object(struct osd_request *, struct osd_obj_id *);
    > +
    > +void osd_req_write(struct osd_request *,
    > + const struct osd_obj_id *, struct bio *data_out, u64 offset);
    > +void osd_req_append(struct osd_request *,
    > + const struct osd_obj_id *, struct bio *data_out);/* NI */
    > +void osd_req_create_write(struct osd_request *,
    > + const struct osd_obj_id *, struct bio *data_out, u64 offset);/* NI */
    > +void osd_req_clear(struct osd_request *,
    > + const struct osd_obj_id *, u64 offset, u64 len);/* NI */
    > +void osd_req_punch(struct osd_request *,
    > + const struct osd_obj_id *, u64 offset, u64 len);/* V2-only NI */
    > +
    > +void osd_req_flush_object(struct osd_request *,
    > + const struct osd_obj_id *, enum osd_options_flush_scope_values,
    > + /*V2*/ u64 offset, /*V2*/ u64 len);
    > +
    > +void osd_req_read(struct osd_request *,
    > + const struct osd_obj_id *, struct bio *data_in, u64 offset);
    > +
    > +/*
    > + * Root/Partition/Collection/Object Attributes commands
    > + */
    > +
    > +/* get before set */
    > +void osd_req_get_attributes(struct osd_request *, const struct osd_obj_id *);
    > +
    > +/* set before get */
    > +void osd_req_set_attributes(struct osd_request *, const struct osd_obj_id *);
    > +
    > +/*
    > + * Attributes appended to most commands
    > + */
    > +
    > +/* Attributes List mode (or V2 CDB) */
    > + /*
    > + * TODO: In ver2 if at finalize time only one attr was set and no gets,
    > + * then the Attributes CDB mode is used automatically to save IO.
    > + */
    > +
    > +/* set a list of attributes. */
    > +int osd_req_add_set_attr_list(struct osd_request *,
    > + const struct osd_attr *, unsigned nelem);
    > +
    > +/* get a list of attributes */
    > +int osd_req_add_get_attr_list(struct osd_request *,
    > + const struct osd_attr *, unsigned nelem);
    > +
    > +/*
    > + * Attributes list decoding
    > + * Must be called after osd_request.request was executed
    > + * It is called in a loop to decode the returned get_attr
    > + * (see osd_add_get_attr)
    > + */
    > +int osd_req_decode_get_attr_list(struct osd_request *,
    > + struct osd_attr *, int *nelem, void **iterator);
    > +
    > +/* Attributes Page mode */
    > +
    > +/*
    > + * Read an attribute page and optionally set one attribute
    > + *
    > + * Retrieves the attribute page directly to a user buffer.
    > + * @attr_page_data shall stay valid until end of execution.
    > + * See osd_attributes.h for common page structures
    > + */
    > +int osd_req_add_get_attr_page(struct osd_request *,
    > + u32 page_id, void *attr_page_data, unsigned max_page_len,
    > + const struct osd_attr *set_one);
    > +
    > +#endif /* __OSD_LIB_H__ */
    > diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h
    > new file mode 100644
    > index 0000000..77a74a3
    > --- /dev/null
    > +++ b/include/scsi/osd_protocol.h
    > @@ -0,0 +1,497 @@
    > +/*
    > + * osd_protocol.h - OSD T10 standard C definitions.
    > + *
    > + * Copyright (C) 2008 Panasas Inc. All rights reserved.
    > + *
    > + * Authors:
    > + * Boaz Harrosh
    > + * Benny Halevy
    > + *
    > + * This program is free software; you can redistribute it and/or modify
    > + * it under the terms of the GNU General Public License version 2
    > + *
    > + * This file contains types and constants that are defined by the protocol
    > + * Note: All names and symbols are taken from the OSD standard's text.
    > + */
    > +#ifndef __OSD_PROTOCOL_H__
    > +#define __OSD_PROTOCOL_H__
    > +
    > +#include
    > +#include
    > +#include
    > +
    > +enum {
    > + OSDv1_ADDITIONAL_CDB_LENGTH = 192,
    > + OSDv1_TOTAL_CDB_LEN = OSDv1_ADDITIONAL_CDB_LENGTH + 8,
    > + OSDv1_CAP_LEN = 80,
    > + /* Latest supported version */
    > + OSD_ADDITIONAL_CDB_LENGTH = OSDv1_ADDITIONAL_CDB_LENGTH,
    > + OSD_TOTAL_CDB_LEN = OSDv1_TOTAL_CDB_LEN,
    > + OSD_CAP_LEN = OSDv1_CAP_LEN,
    > +
    > + OSD_SYSTEMID_LEN = 20,
    > + OSD_CRYPTO_KEYID_SIZE = 20,
    > + OSD_CRYPTO_SEED_SIZE = 4,
    > + OSD_CRYPTO_NONCE_SIZE = 12,
    > + OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */
    > +
    > + OSD_PARTITION_FIRST_ID = 0x10000,
    > + OSD_OBJECT_FIRST_ID = 0x10000,
    > +};
    > +
    > +/* (osd-r10 5.2.4)
    > + * osd2r03: 5.2.3 Caching control bits
    > + */
    > +enum osd_options_byte {
    > + OSD_CDB_FUA = 0x08, /* Force Unit Access */
    > + OSD_CDB_DPO = 0x10, /* Disable Page Out */
    > +};
    > +
    > +/*
    > + * osd2r03: 5.2.5 Isolation.
    > + * First 3 bits, V2-only.
    > + * Also for attr 110h "default isolation method" at Root Information page
    > + */
    > +enum osd_options_byte_isolation {
    > + OSD_ISOLATION_DEFAULT = 0,
    > + OSD_ISOLATION_NONE = 1,
    > + OSD_ISOLATION_STRICT = 2,
    > + OSD_ISOLATION_RANGE = 4,
    > + OSD_ISOLATION_FUNCTIONAL = 5,
    > + OSD_ISOLATION_VENDOR = 7,
    > +};
    > +
    > +/* (osd-r10: 6.7)
    > + * osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
    > + */
    > +enum osd_options_flush_scope_values {
    > + OSD_CDB_FLUSH_ALL = 0,
    > + OSD_CDB_FLUSH_ATTR_ONLY = 1,
    > +
    > + OSD_CDB_FLUSH_ALL_RECURSIVE = 2,
    > + /* V2-only */
    > + OSD_CDB_FLUSH_ALL_RANGE = 2,
    > +};
    > +
    > +/* osd2r03: 5.2.10 Timestamps control */
    > +enum {
    > + OSD_CDB_NORMAL_TIMESTAMPS = 0,
    > + OSD_CDB_BYPASS_TIMESTAMPS = 0x7f,
    > +};
    > +
    > +/* (osd-r10: 5.2.2.1)
    > + * osd2r03: 5.2.4.1 Get and set attributes CDB format selection
    > + * 2 bits at second nibble of command_specific_options byte
    > + */
    > +enum osd_attributes_mode {
    > + /* V2-only */
    > + OSD_CDB_SET_ONE_ATTR = 0x10,
    > +
    > + OSD_CDB_GET_ATTR_PAGE_SET_ONE = 0x20,
    > + OSD_CDB_GET_SET_ATTR_LISTS = 0x30,
    > +
    > + OSD_CDB_GET_SET_ATTR_MASK = 0x30,
    > +};
    > +
    > +/* (osd-r10: 4.12.5)
    > + * osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
    > + * byte offset = mantissa * (2^(exponent+8))
    > + * struct {
    > + * unsigned mantissa: 28;
    > + * int exponent: 04;
    > + * }
    > + */
    > +typedef __be32 __bitwise osd_cdb_offset;
    > +
    > +enum {
    > + OSD_OFFSET_UNUSED = 0xFFFFFFFF,
    > + OSD_OFFSET_MAX_BITS = 28,
    > +
    > + OSDv1_OFFSET_MIN_SHIFT = 8,
    > + OSD_OFFSET_MAX_SHIFT = 16,
    > +};
    > +
    > +/* Return the smallest allowed encoded offset that contains @offset.
    > + *
    > + * The actual encoded offset returned is @offset + *padding.
    > + * (up to max_shift, non-inclusive)
    > + */
    > +osd_cdb_offset __osd_encode_offset(u64 offset, unsigned *padding,
    > + int min_shift, int max_shift);
    > +
    > +/* Minimum alignment is 256 bytes
    > + * Note: Seems from std v1 that exponent can be from 0+8 to 0xE+8 (inclusive)
    > + * which is 8 to 23 but IBM code restricts it to 16, so be it.
    > + */
    > +static inline osd_cdb_offset osd_encode_offset_v1(u64 offset, unsigned *padding)
    > +{
    > + return __osd_encode_offset(offset, padding,
    > + OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
    > +}
    > +
    > +/* osd2r03: 5.2.1 Overview */
    > +struct osd_cdb_head {
    > + struct scsi_varlen_cdb_hdr varlen_cdb;
    > +/*10*/ u8 options;
    > + u8 command_specific_options;
    > + u8 timestamp_control;
    > +/*13*/ u8 reserved1[3];
    > +/*16*/ __be64 partition;
    > +/*24*/ __be64 object;
    > +/*32*/ union { /* V1 vs V2 alignment differences */
    > + struct __osdv1_cdb_addr_len {
    > +/*32*/ __be32 list_identifier;/* Rarely used */
    > +/*36*/ __be64 length;
    > +/*44*/ __be64 start_address;
    > + } __packed v1;
    > + };
    > +/*52*/ union { /* selected attributes mode Page/List/Single */
    > + struct osd_attributes_page_mode {
    > +/*52*/ __be32 get_attr_page;
    > +/*56*/ __be32 get_attr_alloc_length;
    > +/*60*/ osd_cdb_offset get_attr_offset;
    > +
    > +/*64*/ __be32 set_attr_page;
    > +/*68*/ __be32 set_attr_id;
    > +/*72*/ __be32 set_attr_length;
    > +/*76*/ osd_cdb_offset set_attr_offset;
    > + } __packed attrs_page;
    > +
    > + struct osd_attributes_list_mode {
    > +/*52*/ __be32 get_attr_desc_bytes;
    > +/*56*/ osd_cdb_offset get_attr_desc_offset;
    > +
    > +/*60*/ __be32 get_attr_alloc_length;
    > +/*64*/ osd_cdb_offset get_attr_offset;
    > +
    > +/*68*/ __be32 set_attr_bytes;
    > +/*72*/ osd_cdb_offset set_attr_offset;
    > + __be32 not_used;
    > + } __packed attrs_list;
    > +
    > + /* osd2r03:5.2.4.2 Set one attribute value using CDB fields */
    > + struct osd_attributes_cdb_mode {
    > +/*52*/ __be32 set_attr_page;
    > +/*56*/ __be32 set_attr_id;
    > +/*60*/ __be16 set_attr_len;
    > +/*62*/ u8 set_attr_val[80-62];
    > + } __packed attrs_cdb;
    > +/*52*/ u8 get_set_attributes_parameters[80-52];
    > + };
    > +} __packed;
    > +/*80*/
    > +
    > +/*160 v1*/
    > +struct osd_security_parameters {
    > +/*160*/u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
    > +/*180*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
    > +/*192*/osd_cdb_offset data_in_integrity_check_offset;
    > +/*196*/osd_cdb_offset data_out_integrity_check_offset;
    > +} __packed;
    > +/*200 v1*/
    > +
    > +struct osdv1_cdb {
    > + struct osd_cdb_head h;
    > + u8 caps[OSDv1_CAP_LEN];
    > + struct osd_security_parameters sec_params;
    > +} __packed;
    > +
    > +struct osd_cdb {
    > + union {
    > + struct osdv1_cdb v1;
    > + u8 buff[OSD_TOTAL_CDB_LEN];
    > + };
    > +} __packed;
    > +
    > +static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
    > +{
    > + return (struct osd_cdb_head *)ocdb->buff;
    > +}
    > +
    > +/* define both version actions
    > + * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
    > + */
    > +#define OSD_ACT___(Name, Num) \
    > + OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), \
    > + OSDv1_ACT_##Name = __constant_cpu_to_be16(0x8800 + Num),
    > +
    > +/* V2 only actions */
    > +#define OSD_ACT_V2(Name, Num) \
    > + OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num),
    > +
    > +#define OSD_ACT_V1_V2(Name, Num1, Num2) \
    > + OSD_ACT_##Name = __constant_cpu_to_be16(Num2), \
    > + OSDv1_ACT_##Name = __constant_cpu_to_be16(Num1),
    > +
    > +enum osd_service_actions {
    > + OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00)
    > + OSD_ACT___(FORMAT_OSD, 0x01)
    > + OSD_ACT___(CREATE, 0x02)
    > + OSD_ACT___(LIST, 0x03)
    > + OSD_ACT_V2(PUNCH, 0x04)
    > + OSD_ACT___(READ, 0x05)
    > + OSD_ACT___(WRITE, 0x06)
    > + OSD_ACT___(APPEND, 0x07)
    > + OSD_ACT___(FLUSH, 0x08)
    > + OSD_ACT_V2(CLEAR, 0x09)
    > + OSD_ACT___(REMOVE, 0x0A)
    > + OSD_ACT___(CREATE_PARTITION, 0x0B)
    > + OSD_ACT___(REMOVE_PARTITION, 0x0C)
    > + OSD_ACT___(GET_ATTRIBUTES, 0x0E)
    > + OSD_ACT___(SET_ATTRIBUTES, 0x0F)
    > + OSD_ACT___(CREATE_AND_WRITE, 0x12)
    > + OSD_ACT___(CREATE_COLLECTION, 0x15)
    > + OSD_ACT___(REMOVE_COLLECTION, 0x16)
    > + OSD_ACT___(LIST_COLLECTION, 0x17)
    > + OSD_ACT___(SET_KEY, 0x18)
    > + OSD_ACT___(SET_MASTER_KEY, 0x19)
    > + OSD_ACT___(FLUSH_COLLECTION, 0x1A)
    > + OSD_ACT___(FLUSH_PARTITION, 0x1B)
    > + OSD_ACT___(FLUSH_OSD, 0x1C)
    > +
    > + OSD_ACT_V2(QUERY, 0x20)
    > + OSD_ACT_V2(REMOVE_MEMBER_OBJECTS, 0x21)
    > + OSD_ACT_V2(GET_MEMBER_ATTRIBUTES, 0x22)
    > + OSD_ACT_V2(SET_MEMBER_ATTRIBUTES, 0x23)
    > + OSD_ACT_V2(READ_MAP, 0x31)
    > +
    > + OSD_ACT_V1_V2(PERFORM_SCSI_COMMAND, 0x8F7E, 0x8F7C)
    > + OSD_ACT_V1_V2(SCSI_TASK_MANAGEMENT, 0x8F7F, 0x8F7D)
    > + /* 0x8F80 to 0x8FFF are Vendor specific */
    > +};
    > +
    > +/* osd2r03: 7.1.3.2 List entry format for retrieving attributes */
    > +struct osd_attributes_list_attrid {
    > + __be32 page;
    > + __be32 attr_id;
    > +} __packed;
    > +
    > +/*
    > + * osd2r03: 7.1.3.3 List entry format for retrieved attributes and
    > + * for setting attributes
    > + */
    > +struct osd_attributes_list_element {
    > + __be32 page;
    > + __be32 attr_id;
    > + __be16 attr_bytes;
    > + u8 attr_val[0];
    > +} __packed;
    > +
    > +enum {
    > + OSDv1_ATTRIBUTES_ELEM_ALIGN = 1,
    > +};
    > +
    > +enum {
    > + OSD_ATTR_LIST_ALL_PAGES = 0xFFFFFFFF,
    > + OSD_ATTR_LIST_ALL_IN_PAGE = 0xFFFFFFFF,
    > +};
    > +
    > +static inline unsigned osdv1_attr_list_elem_size(unsigned len)
    > +{
    > + return ALIGN(len + sizeof(struct osd_attributes_list_element),
    > + OSDv1_ATTRIBUTES_ELEM_ALIGN);
    > +}
    > +
    > +/*
    > + * osd2r03: 7.1.3 OSD attributes lists (Table 184) — List type values
    > + */
    > +enum osd_attr_list_types {
    > + OSD_ATTR_LIST_GET = 0x1, /* descriptors only */
    > + OSD_ATTR_LIST_SET_RETRIEVE = 0x9, /*descriptors/values variable-length*/
    > + OSD_V2_ATTR_LIST_MULTIPLE = 0xE, /* ver2, Multiple Objects lists*/
    > + OSD_V1_ATTR_LIST_CREATE_MULTIPLE = 0xF,/*ver1, used by create_multple*/
    > +};
    > +
    > +/* osd2r03: 7.1.3.4 Multi-object retrieved attributes format */
    > +struct osd_attributes_list_multi_header {
    > + __be64 object_id;
    > + u8 object_type; /* object_type enum below */
    > + u8 reserved[5];
    > + __be16 list_bytes;
    > + /* followed by struct osd_attributes_list_element's */
    > +};
    > +
    > +struct osdv1_attributes_list_header {
    > + u8 type; /* low 4-bit only */
    > + u8 pad;
    > + __be16 list_bytes; /* Initiator shall set to Zero. Only set by target */
    > + /*
    > + * type=9 followed by struct osd_attributes_list_element's
    > + * type=E followed by struct osd_attributes_list_multi_header's
    > + */
    > +} __packed;
    > +
    > +static inline unsigned osdv1_list_size(struct osdv1_attributes_list_header *h)
    > +{
    > + return be16_to_cpu(h->list_bytes);
    > +}
    > +
    > +/* (osd-r10 6.13)
    > + * osd2r03: 6.15 LIST (Table 79) LIST command parameter data.
    > + * for root_lstchg below
    > + */
    > +enum {
    > + OSD_OBJ_ID_LIST_PAR = 0x1, /* V1-only. Not used in V2 */
    > + OSD_OBJ_ID_LIST_LSTCHG = 0x2,
    > +};
    > +
    > +/*
    > + * osd2r03: 6.15.2 LIST command parameter data
    > + * (Also for LIST COLLECTION)
    > + */
    > +struct osd_obj_id_list {
    > + __be64 list_bytes; /* bytes in list excluding list_bytes (-8) */
    > + __be64 continuation_id;
    > + __be32 list_identifier;
    > + u8 pad[3];
    > + u8 root_lstchg;
    > + __be64 object_ids[0];
    > +} __packed;
    > +
    > +static inline bool osd_is_obj_list_done(struct osd_obj_id_list *list,
    > + bool *is_changed)
    > +{
    > + *is_changed = (0 != (list->root_lstchg & OSD_OBJ_ID_LIST_LSTCHG));
    > + return 0 != list->continuation_id;
    > +}
    > +
    > +/*
    > + * osd2r03: 4.12.4.5 The ALLDATA security method
    > + */
    > +struct osd_data_out_integrity_info {
    > + __be64 data_bytes;
    > + __be64 set_attributes_bytes;
    > + __be64 get_attributes_bytes;
    > + __be64 integrity_check_value;
    > +} __packed;
    > +
    > +struct osd_data_in_integrity_info {
    > + __be64 data_bytes;
    > + __be64 retrieved_attributes_bytes;
    > + __be64 integrity_check_value;
    > +} __packed;
    > +
    > +struct osd_timestamp {
    > + u8 time[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */
    > +} __packed;
    > +/* FIXME: define helper functions to convert to/from osd time format */
    > +
    > +/*
    > + * Capability & Security definitions
    > + * osd2r03: 4.11.2.2 Capability format
    > + * osd2r03: 5.2.8 Security parameters
    > + */
    > +
    > +struct osd_key_identifier {
    > + u8 id[7]; /* if you know why 7 please email bharrosh@panasas.com */
    > +} __packed;
    > +
    > +/* for osd_capability.format */
    > +enum {
    > + OSD_SEC_CAP_FORMAT_NO_CAPS = 0,
    > + OSD_SEC_CAP_FORMAT_VER1 = 1,
    > + OSD_SEC_CAP_FORMAT_VER2 = 2,
    > +};
    > +
    > +/* security_method */
    > +enum {
    > + OSD_SEC_NOSEC = 0,
    > + OSD_SEC_CAPKEY = 1,
    > + OSD_SEC_CMDRSP = 2,
    > + OSD_SEC_ALLDATA = 3,
    > +};
    > +
    > +enum object_type {
    > + OSD_SEC_OBJ_ROOT = 0x1,
    > + OSD_SEC_OBJ_PARTITION = 0x2,
    > + OSD_SEC_OBJ_COLLECTION = 0x40,
    > + OSD_SEC_OBJ_USER = 0x80,
    > +};
    > +
    > +enum osd_capability_bit_masks {
    > + OSD_SEC_CAP_APPEND = (1 << 0),
    > + OSD_SEC_CAP_OBJ_MGMT = (1 << 1),
    > + OSD_SEC_CAP_REMOVE = (1 << 2),
    > + OSD_SEC_CAP_CREATE = (1 << 3),
    > + OSD_SEC_CAP_SET_ATTR = (1 << 4),
    > + OSD_SEC_CAP_GET_ATTR = (1 << 5),
    > + OSD_SEC_CAP_WRITE = (1 << 6),
    > + OSD_SEC_CAP_READ = (1 << 7),
    > +
    > + OSD_SEC_CAP_NONE1 = (1 << 8),
    > + OSD_SEC_CAP_NONE2 = (1 << 9),
    > + OSD_SEC_CAP_NONE3 = (1 << 10),
    > + OSD_SEC_CAP_QUERY = (1 << 11), /*v2 only*/
    > + OSD_SEC_CAP_M_OBJECT = (1 << 12), /*v2 only*/
    > + OSD_SEC_CAP_POL_SEC = (1 << 13),
    > + OSD_SEC_CAP_GLOBAL = (1 << 14),
    > + OSD_SEC_CAP_DEV_MGMT = (1 << 15),


    These could use BIT(nr) from bitops.h.

    > +};
    > +
    > +/* for object_descriptor_type (hi nibble used) */
    > +enum {
    > + OSD_SEC_OBJ_DESC_NONE = 0, /* Not allowed */
    > + OSD_SEC_OBJ_DESC_OBJ = 1 << 4, /* v1: also collection */
    > + OSD_SEC_OBJ_DESC_PAR = 2 << 4, /* also root */
    > + OSD_SEC_OBJ_DESC_COL = 3 << 4, /* v2 only */
    > +};
    > +
    > +/* (osd-r10:4.9.2.2)
    > + * osd2r03:4.11.2.2 Capability format
    > + */
    > +struct osd_capability_head {
    > + u8 format; /* low nibble */
    > + u8 integrity_algorithm__key_version; /* MAKE_BYTE(integ_alg, key_ver) */
    > + u8 security_method;
    > + u8 reserved1;
    > +/*04*/ struct osd_timestamp expiration_time;
    > +/*10*/ u8 audit[30-10];
    > +/*30*/ u8 discriminator[42-30];
    > +/*42*/ struct osd_timestamp object_created_time;
    > +/*48*/ u8 object_type;
    > + u8 permissions_bit_mask[54-49];


    The offset comments are OK with me, but please lose the [b-a] length specifiers.


    > +/*54*/ u8 reserved2;
    > +/*55*/ u8 object_descriptor_type; /* high nibble */
    > +} __packed;
    > +
    > +/*56 v1*/
    > +struct osdv1_cap_object_descriptor {
    > + union {
    > + struct {
    > +/*56*/ __be32 policy_access_tag;
    > +/*60*/ __be64 allowed_partition_id;
    > +/*68*/ __be64 allowed_object_id;
    > +/*76*/ __be32 reserved;
    > + } __packed obj_desc;
    > +
    > + u8 object_descriptor[80-56];/*24*/
    > + };
    > +} __packed;
    > +/*80 v1*/
    > +
    > +struct osd_capability {
    > + struct osd_capability_head h;
    > + struct osdv1_cap_object_descriptor od;
    > +} __packed;
    > +
    > +/**
    > + * osd_sec_set_caps - set cap-bits into the capabilities header
    > + *
    > + * @cap: The osd_capability_head to set cap bits to.
    > + * @bit_mask: Use an ORed list of enum osd_capability_bit_masks values
    > + *
    > + * permissions_bit_mask is unaligned use below to set into caps
    > + * in a version independent way
    > + */
    > +static inline void osd_sec_set_caps(struct osd_capability_head *cap,
    > + u16 bit_mask)
    > +{
    > + /*
    > + *Note: The bits above are defined LE order this is because this way
    > + * they can grow in the future to more then 16, and still retain
    > + * there constant values.
    > + */
    > + put_unaligned_le16(bit_mask, &cap->permissions_bit_mask);
    > +}
    > +
    > +#endif /* ndef __OSD_PROTOCOL_H__ */


    ---
    ~Randy
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3