From 3e92d243f8c2b232ceaa13e1e21501df7be5f1b5 Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Mon, 19 Oct 2009 12:39:47 +0200 Subject: [PATCH] osd-target: extension: Let in a system_ID set on LUN format system_ID is a, factory set, unique identifier of an osd-lun. Since osd-target is a software solution we should enable a system administrator setting of the system_id. The solution proposed here is to let a system_id attribute- set while an OSD_FORMAT is preformed on the osd-lun. Rational is: since we are initializing a new backing storage to host the osd-lun we can at this time set it's name, and by that lock it permanently until a new format initializes a new osd. Thous, regular osd utilities can be used to set the system_id and no special command line or config files magic is needed. The system_id set can be up to RIAP_OSD_SYSTEM_ID_LEN bytes in size, and if smaller is zero left-padded. Signed-off-by: Boaz Harrosh --- osd-target/osd.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/osd-target/osd.c b/osd-target/osd.c index e1e47e9..0080f21 100644 --- a/osd-target/osd.c +++ b/osd-target/osd.c @@ -701,8 +701,15 @@ static int get_riap(struct osd_device *osd, uint64_t pid, uint64_t oid, val = name; break; case RIAP_OSD_SYSTEM_ID: - len = RIAP_OSD_SYSTEM_ID_LEN; - val = "\xf1\x81\x00\x0eOSC OSDEMU\x00\x00"; + ret = attr_get_attr(osd->dbc, pid, oid, ROOT_INFO_PG, + RIAP_OSD_SYSTEM_ID_LEN, outlen, outbuf, + listfmt, used_outlen); + if (ret == -ENOENT) { + len = RIAP_OSD_SYSTEM_ID_LEN; + val = "\xf1\x81\x00\x0eOSC OSDEMU\x00\x00"; + } else { + return ret; + } break; case RIAP_VENDOR_IDENTIFICATION: len = sizeof("OSC"); @@ -781,7 +788,6 @@ static int set_riap(struct osd_device *osd, uint64_t pid, uint64_t oid, { switch (number) { /* read only */ - case RIAP_OSD_SYSTEM_ID: case RIAP_VENDOR_IDENTIFICATION: case RIAP_PRODUCT_IDENTIFICATION: case RIAP_PRODUCT_MODEL: @@ -793,6 +799,27 @@ static int set_riap(struct osd_device *osd, uint64_t pid, uint64_t oid, default: return OSD_ERROR; + /* osd-target extension: We let in a system_ID set on LUN + * format command. + */ + case RIAP_OSD_SYSTEM_ID: + if (osd->ccap.cdb_srvc_act == OSD_FORMAT_OSD) { + char system_id[RIAP_OSD_SYSTEM_ID_LEN]; + + if (len > RIAP_OSD_SYSTEM_ID_LEN) + return -EINVAL; + + if (len < RIAP_OSD_SYSTEM_ID_LEN) { + memcpy(system_id, val, len); + memset(system_id + len, 0, + RIAP_OSD_SYSTEM_ID_LEN - len); + val = system_id; + } + return attr_set_attr(osd->dbc, 0, 0, ROOT_INFO_PG, + RIAP_OSD_SYSTEM_ID, val, + RIAP_OSD_SYSTEM_ID_LEN); + } else + return OSD_ERROR; case RIAP_OSD_NAME: { char osdname[64];