Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updated osd-util and osd-initiator
* Not tested the functionality yet
  • Loading branch information
cengizk committed Jun 13, 2014
1 parent 4ad0c42 commit 749e802
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 126 deletions.
58 changes: 36 additions & 22 deletions osd-initiator/command.c
Expand Up @@ -222,13 +222,14 @@ int osd_command_set_get_attributes(struct osd_command *command, uint64_t pid,
return 0;
}


int osd_command_set_get_member_attributes(struct osd_command *command,
uint64_t pid, uint64_t cid)
uint64_t pid, uint64_t cid, uint64_t min_oid, uint64_t max_oid)
{
varlen_cdb_init(command, OSD_GET_MEMBER_ATTRIBUTES);
set_htonll(&command->cdb[16], pid);
set_htonll(&command->cdb[24], cid);
set_htonll(&command->cdb[32], min_oid);
set_htonll(&command->cdb[40], max_oid);
return 0;
}

Expand Down Expand Up @@ -503,18 +504,25 @@ struct attr_malloc_header {
* After the command completes, call the resolve function to fill in
* the results and free the temp buffers.
*/

int osd_command_attr_build(struct osd_command *command,
const struct attribute_list *attr, int numattr)
{
return osd_command_multi_attr_build(command, attr, numattr, 1);
}

int osd_command_multi_attr_build(struct osd_command *command,
const struct attribute_list *attr, int numattr, int numobj)
{
int use_getpage, use_set_one_attr = 0;
int numget, numgetpage, numgetmulti, numset, numresult;
uint32_t getsize, getpagesize, getmultisize, setsize, resultsize;
uint32_t getmulti_num_objects = 0;
uint32_t getmulti_num_objects = 1;
struct attr_malloc_header *header;
uint8_t *p, *extra_out_buf, *extra_in_buf;
struct bsg_iovec *iov;

int i;
int i, j;
int neediov;
int setattr_index;
uint64_t extra_out, extra_in;
Expand Down Expand Up @@ -549,7 +557,7 @@ int osd_command_attr_build(struct osd_command *command,
uint64_t size_pad_outdata_alloc;
uint64_t size_pad_indata_alloc;
uint64_t extra_out_alloc, extra_in_alloc;

if (numattr == 0)
return 0;

Expand Down Expand Up @@ -583,7 +591,6 @@ int osd_command_attr_build(struct osd_command *command,
return -EINVAL;
}
}

if (numgetpage) {
if (numgetpage > 1) {
osd_error("%s: only one ATTR_GET_PAGE at a time",
Expand Down Expand Up @@ -624,13 +631,13 @@ int osd_command_attr_build(struct osd_command *command,
__func__);
return -EINVAL;
}
if (action != OSD_CREATE) {
if (action != OSD_CREATE && action != OSD_GET_MEMBER_ATTRIBUTES) {
osd_error(
"%s: ATTR_GET_MULTI must only be used with CREATE",
"%s: ATTR_GET_MULTI must only be used with CREATE or GET_MEMBER_ATTRIBUTES",
__func__);
return -EINVAL;
}
getmulti_num_objects = get_ntohs(&command->cdb[36]);
getmulti_num_objects = numobj;
}
use_getpage = 0;
if (numget == 0 && numgetmulti == 0 && numset == 1) {
Expand Down Expand Up @@ -687,7 +694,7 @@ int osd_command_attr_build(struct osd_command *command,
size_pad_setlist = start_getlist - prev;
if (size_setlist == 0)
size_pad_outdata_alloc = roundup8(size_pad_setlist);
size_getlist = 8 + 8 * (numget + numgetmulti);
size_getlist = 8 + 8 * getmulti_num_objects * (numget + numgetmulti);
}

extra_out = size_pad_outdata + size_setlist
Expand All @@ -714,7 +721,7 @@ int osd_command_attr_build(struct osd_command *command,
if (numgetpage)
size_retrieved = getpagesize; /* no rounding */
if (numgetmulti)
size_retrieved = 8 + getmultisize *
size_retrieved = 8 + (getmultisize + 16) *
getmulti_num_objects;
if (numresult) {
if (!size_retrieved)
Expand Down Expand Up @@ -875,13 +882,15 @@ int osd_command_attr_build(struct osd_command *command,
*/
if (numget || numgetmulti) {
uint8_t *q = p + 8;
for (i=0; i<numattr; i++) {
if (!(attr[i].type == ATTR_GET_MULTI
|| attr[i].type == ATTR_GET))
continue;
set_htonl(&q[0], attr[i].page);
set_htonl(&q[4], attr[i].number);
q += 8;
for (j=0; j<getmulti_num_objects; j++) {
for (i=0; i<numattr; i++) {
if (!(attr[i].type == ATTR_GET_MULTI
|| attr[i].type == ATTR_GET))
continue;
set_htonl(&q[0], attr[i].page);
set_htonl(&q[4], attr[i].number);
q += 8;
}
}
memset(p, 0, 8);
p[0] = 0x1;
Expand Down Expand Up @@ -931,6 +940,7 @@ int osd_command_attr_build(struct osd_command *command,
set_htonoffset(&command->cdb[64], start_retrieved);
set_htonl(&command->cdb[68], size_setlist);
set_htonoffset(&command->cdb[72], start_setlist);
set_htonl(&command->cdb[80], numobj);
}

/*
Expand Down Expand Up @@ -1065,14 +1075,14 @@ int osd_command_attr_resolve(struct osd_command *command)
__func__);
goto unwind;
}
} else if ((p[0] & 0xf) == 0xf) {
} else if ((p[0] & 0xf) == 0xe) {
if (!numgetmulti) {
osd_error("%s: got list type f, not expecting multi",
osd_error("%s: got list type e, not expecting multi",
__func__);
goto unwind;
}
} else {
osd_error("%s: expecting list type 9 or f, got 0x%x",
osd_error("%s: expecting list type 9 or e, got 0x%x",
__func__, p[0] & 0xf);
goto unwind;
}
Expand Down Expand Up @@ -1100,7 +1110,8 @@ int osd_command_attr_resolve(struct osd_command *command)
break;
if (numgetmulti) {
oid = get_ntohll(&p[0]);
p += 8;
p += 16;
len -= 16;
}
page = get_ntohl(&p[0]);
number = get_ntohl(&p[4]);
Expand Down Expand Up @@ -1147,7 +1158,10 @@ int osd_command_attr_resolve(struct osd_command *command)

mr->oid[mr->numoid] = oid;
mr->val[mr->numoid] = avail_len ? p : NULL;
//osd_debug("%d\n", mr->oid[mr->numoid]);
//osd_debug("%d\n", get_ntohll(((struct attribute_get_multi_results *)attr[i].val)->val[((struct attribute_get_multi_results *)attr[i].val)->numoid]));
mr->outlen[mr->numoid] = avail_len;
//osd_debug("%d\n", mr->outlen[mr->numoid]);
++mr->numoid;
} else {
attr[i].val = avail_len ? p : NULL;
Expand Down
6 changes: 4 additions & 2 deletions osd-initiator/command.h
Expand Up @@ -59,7 +59,7 @@ struct attribute_get_multi_results {
and just set to point to the scsi/sg.h sg_iovec (which is ignored
in the kernel
*/
#ifdef __APPLE__
#if 0
/*
* This is copied from a kernel header to avoid including it.
*/
Expand Down Expand Up @@ -129,7 +129,7 @@ int osd_command_set_format_osd(struct osd_command *command, uint64_t capacity);
int osd_command_set_get_attributes(struct osd_command *command, uint64_t pid,
uint64_t oid);
int osd_command_set_get_member_attributes(struct osd_command *command,
uint64_t pid, uint64_t cid);
uint64_t pid, uint64_t cid, uint64_t min_oid, uint64_t max_oid);
int osd_command_set_list(struct osd_command *command, uint64_t pid,
uint32_t list_id, uint64_t alloc_len,
uint64_t initial_oid, int list_attr);
Expand Down Expand Up @@ -185,6 +185,8 @@ int osd_command_set_cond_setattr(struct osd_command *command, uint64_t pid,
/* Attributes */
int osd_command_attr_build(struct osd_command *command,
const struct attribute_list *const attrs, int num);
int osd_command_multi_attr_build(struct osd_command *command,
const struct attribute_list *const attrs, int num, int numobj);
int osd_command_attr_resolve(struct osd_command *command);
void osd_command_attr_free(struct osd_command *command);

Expand Down
31 changes: 31 additions & 0 deletions osd-initiator/drivelist.c
Expand Up @@ -24,6 +24,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <netdb.h>

#include "osd-util/osd-util.h"
#include "command.h"
Expand Down Expand Up @@ -151,6 +152,36 @@ int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives)
++count;
}

/* grab the hostname from the fs.conf file */
int i=0, j;
int condition=1;
char *string[200];
char *line;
FILE *file;
file = fopen("/usr/src/fs.conf", "r");
line = (char *) malloc(120);

while(condition != EOF)
{
condition = fscanf(file, "%s", line);
if(condition != EOF)
{
string[i]=(char *) malloc(120);
strcpy(string[i], line);
if(!strncmp(string[i], "osd://", 5))
{

for(j = 0; j < count; j++) {
if(!strcmp(&(line[6]), ret[j].targetname))
ret[j].hostname = strdup(string[i-1]);
}
}
i++;
}
}

fclose(file);

out:
if (toplevel)
closedir(toplevel);
Expand Down
1 change: 1 addition & 0 deletions osd-initiator/drivelist.h
Expand Up @@ -21,6 +21,7 @@
struct osd_drive_description {
char *targetname;
char *chardev;
char *hostname;
};

int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives);
Expand Down
2 changes: 1 addition & 1 deletion osd-initiator/python/Makefile
Expand Up @@ -15,7 +15,7 @@ else
# mad guess
INCDIR := -I/usr/include/python2.4
endif
INCDIR += -I../..
INCDIR += -I../.. -I../
OSDLIBS := ../libosdinit.a ../../osd-util/libosdutil.a

-include ../../Makedefs
Expand Down
7 changes: 2 additions & 5 deletions osd-initiator/python/command.c
Expand Up @@ -462,10 +462,7 @@ static PyObject *pyosd_command_set_flush(PyObject *self, PyObject *args)
}

py_command->set = 1;

/* FIXME: scope=2 needs a start/length params should read these in too
osd_command_set_flush(command, pid, oid, scope);*/
osd_command_set_flush(command, pid, 0, 0, oid, 0);
osd_command_set_flush(command, pid,0, 0, oid, scope);
Py_IncRef(self);
return self;
}
Expand Down Expand Up @@ -586,7 +583,7 @@ static PyObject *pyosd_command_set_get_member_attributes(PyObject *self,
}

py_command->set = 1;
osd_command_set_get_member_attributes(command, pid, cid);
osd_command_set_get_member_attributes(command, pid, cid, 0, 1);
Py_IncRef(self);
return self;
}
Expand Down
5 changes: 5 additions & 0 deletions osd-initiator/python/drivelist.c
Expand Up @@ -20,6 +20,7 @@
#include "osd-initiator/command.h"
#include "osd-initiator/drivelist.h"
#include "pyosd.h"
#include "osd-util/osd-util.h"

/*
* OSDDrive type.
Expand All @@ -28,6 +29,7 @@ struct pyosd_drive {
PyObject_HEAD;
PyObject *targetname;
PyObject *chardev;
PyObject *hostname;
};

/*
Expand Down Expand Up @@ -64,6 +66,7 @@ static int pyosd_drivelist_init(PyObject *self, PyObject *args,
drive = PyObject_New(typeof(*drive), &pyosd_drive_type);
drive->targetname = PyString_FromString(drives[i].targetname);
drive->chardev = PyString_FromString(drives[i].chardev);
drive->hostname = PyString_FromString(drives[i].hostname);
Py_INCREF(drive);
PyList_Append(self, (PyObject *) drive);
}
Expand All @@ -80,6 +83,8 @@ struct PyMemberDef pyosd_drive_members[] = {
READONLY, "target name" },
{ "chardev", T_OBJECT, offsetof(struct pyosd_drive, chardev),
READONLY, "character device" },
{ "hostname", T_OBJECT, offsetof(struct pyosd_drive, hostname),
READONLY, "hostname" },
{ NULL }
};

Expand Down
52 changes: 42 additions & 10 deletions osd-initiator/python/pvfs-init.py
Expand Up @@ -68,7 +68,11 @@ def usage():

set_progname(sys.argv[0])

# defaults
root_handle = 0
fsconf = False
osddirtype = "pvfs"
coll_object = False
if len(sys.argv) == 4 or len(sys.argv) == 6:
devname = sys.argv[1];
datalb = int(sys.argv[2]);
Expand All @@ -79,10 +83,33 @@ if len(sys.argv) == 4 or len(sys.argv) == 6:
else:
usage()

# figure out if we are using a collection object to represent directories
# or not

if fsconf:
osddirtype = False
coll_object = False
get_next_osddir = False
get_next_coll = False
fh = open(fsconf, "r")
buf = fh.read()
fh.close()
for word in buf.split():
if get_next_osddir == True:
osddirtype = word
get_next_osddir = False
if get_next_coll == True:
coll_object = word
get_next_coll = False
if "OSDDirType" == word:
get_next_osddir = True
if "CollectionObject" == word:
get_next_coll = True

drives = OSDDriveList()
dev = False
for d in drives:
if d.targetname == devname:
if d.hostname == devname:
dev = OSDDevice(d.chardev)
break
if not dev:
Expand All @@ -107,22 +134,27 @@ run(OSDCommand().set_format_osd(1<<30))
# one to the highest allocated handle and return that, and do not
# allocate and free so many that it would wrap.
run(OSDCommand().set_create_partition(PVFS_OSD_DATA_PID))
run(OSDCommand().set_create(PVFS_OSD_DATA_PID, datalb))

run(OSDCommand().set_create_partition(PVFS_OSD_META_PID))
if osddirtype == "pvfs":
cid = COLLECTION_OID_LB
run(OSDCommand().set_create_collection(PVFS_OSD_DATA_PID, cid))
run(OSDCommand().set_create_partition(PVFS_OSD_META_PID))
if metalb != root_handle:
run(OSDCommand().set_create(PVFS_OSD_META_PID, metalb))

# create root handle, the top level directory
if root_handle:
command = OSDCommand().set_create(PVFS_OSD_META_PID, root_handle)
if coll_object == "yes":
command = OSDCommand().set_create_collection(PVFS_OSD_META_PID, root_handle)

else:
command = OSDCommand().set_create(PVFS_OSD_META_PID, root_handle)
command.attr_build([ \
OSDAttr(ATTR_SET, PVFS_USEROBJECT_ATTR_PG, 0, 0), \
OSDAttr(ATTR_SET, PVFS_USEROBJECT_ATTR_PG, 1, 0), \
OSDAttr(ATTR_SET, PVFS_USEROBJECT_ATTR_PG, 2, 0777), \
OSDAttr(ATTR_SET, PVFS_USEROBJECT_ATTR_PG, 3, \
OSDAttr(ATTR_SET, ANY_PG + PVFS_USEROBJECT_ATTR_PG, 0, 0), \
OSDAttr(ATTR_SET, ANY_PG + PVFS_USEROBJECT_ATTR_PG, 1, 0), \
OSDAttr(ATTR_SET, ANY_PG + PVFS_USEROBJECT_ATTR_PG, 2, 0777), \
OSDAttr(ATTR_SET, ANY_PG + PVFS_USEROBJECT_ATTR_PG, 3, \
PVFS_ATTR_COMMON_ALL), \
OSDAttr(ATTR_SET, PVFS_USEROBJECT_ATTR_PG, 4, \
OSDAttr(ATTR_SET, ANY_PG + PVFS_USEROBJECT_ATTR_PG, 4, \
PVFS_TYPE_DIRECTORY), \
])
run(command)
Expand Down

0 comments on commit 749e802

Please sign in to comment.