Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added command line interface to interact with an OSD
  • Loading branch information
joc02012 committed Jul 9, 2014
1 parent 6235eac commit f827899
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 28 deletions.
6 changes: 3 additions & 3 deletions osd-initiator/drivelist.c
Expand Up @@ -152,7 +152,7 @@ int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives)
++count;
}

/* grab the hostname from the fs.conf file */
/* For PVFS - grab the hostname from the fs.conf file */
int i=0, j;
int condition=1;
char *string[200];
Expand All @@ -165,7 +165,7 @@ int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives)
file = fopen(conf_path, "r");
line = (char *) malloc(120);

while(condition != EOF)
while(file && condition != EOF)
{
condition = fscanf(file, "%s", line);
if(condition != EOF)
Expand All @@ -183,7 +183,7 @@ int osd_get_drive_list(struct osd_drive_description **drives, int *num_drives)
}
}

fclose(file);
if (file) fclose(file);

out:
if (toplevel)
Expand Down
39 changes: 30 additions & 9 deletions osd-initiator/sync.c
Expand Up @@ -44,6 +44,7 @@ static int check_response(int ret, struct osd_command *command,
command->status, command->sense_len, command->inlen);
osd_error("%s ", osd_sense_as_string(command->sense,
command->sense_len));
return 1;

} else if (command->inlen > 0) {
osd_debug("Successfully performed task. BUF: <<%s>>", buf);
Expand Down Expand Up @@ -79,15 +80,14 @@ static int submit_command(int fd, struct osd_command *command,
ret = osd_submit_and_wait(fd, command);
osd_debug("....retrieving response");
}
check_response(ret, &command, buf);
ret = check_response(ret, command, buf);

return ret;
}

int inquiry(int fd)
{
const int INQUIRY_RSP_LEN = 80;
int ret;
uint8_t inquiry_rsp[INQUIRY_RSP_LEN];
struct osd_command command;

Expand Down Expand Up @@ -140,7 +140,7 @@ int query(int fd, uint64_t pid, uint64_t cid, const uint8_t *query)
}

int create_osd(int fd, uint64_t pid, uint64_t requested_oid,
uint16_t num_user_objects)
uint16_t num_user_objects, uint64_t *assigned_oid)
{
struct osd_command command;

Expand All @@ -154,6 +154,12 @@ int create_osd(int fd, uint64_t pid, uint64_t requested_oid,

submit_command(fd, &command, NULL);

if (assigned_oid != NULL) {
osd_command_attr_resolve(&command);
*assigned_oid = get_ntohll(command.attr[0].val);
osd_command_attr_free(&command);
}

return 0;
}

Expand Down Expand Up @@ -248,9 +254,17 @@ int remove_member_objects(int fd, uint64_t pid, uint64_t cid)
}

int create_and_write_osd(int fd, uint64_t pid, uint64_t requested_oid,
const uint8_t *buf, uint64_t len, uint64_t offset)
const uint8_t *buf, uint64_t len, uint64_t offset,
uint64_t *assigned_oid)
{
struct osd_command command;
struct attribute_list attr = {
.type = ATTR_GET,
.page = CUR_CMD_ATTR_PG,
.number = CCAP_OID,
.len = 8,
};
int ret;

osd_debug("****** CREATE / WRITE ******");
osd_debug("PID: %llu OID: %llu BUF: %s", llu(pid), llu(requested_oid),
Expand All @@ -269,9 +283,18 @@ int create_and_write_osd(int fd, uint64_t pid, uint64_t requested_oid,
command.outdata = buf;
command.outlen = len;

submit_command(fd, &command, NULL);
if (assigned_oid != NULL)
osd_command_attr_build(&command, &attr, 1);

ret = submit_command(fd, &command, NULL);

return 0;
if (ret == 0 && assigned_oid != NULL) {
osd_command_attr_resolve(&command);
*assigned_oid = get_ntohll(command.attr[0].val);
osd_command_attr_free(&command);
}

return ret;
}

int create_and_write_sgl_osd(int fd, uint64_t pid, uint64_t requested_oid,
Expand Down Expand Up @@ -559,9 +582,7 @@ int read_osd(int fd, uint64_t pid, uint64_t oid, uint8_t *buf, uint64_t len,
command.indata = buf;
command.inlen_alloc = len;

submit_command(fd, &command, buf);

return 0;
return submit_command(fd, &command, buf);
}

int read_sgl_osd(int fd, uint64_t pid, uint64_t oid, uint8_t *ddt_buf,
Expand Down
5 changes: 3 additions & 2 deletions osd-initiator/sync.h
Expand Up @@ -27,11 +27,12 @@ int inquiry(int fd);
int query(int fd, uint64_t pid, uint64_t cid, const uint8_t *query);
/* Create */
int create_osd(int fd, uint64_t pid, uint64_t requested_oid,
uint16_t num_user_objects);
uint16_t num_user_objects, uint64_t *assigned_oid);
int create_partition(int fd, uint64_t requested_pid);
int create_collection(int fd, uint64_t pid, uint64_t requested_cid);
int create_and_write_osd(int fd, uint64_t pid, uint64_t requested_oid,
const uint8_t *buf, uint64_t len, uint64_t offset);
const uint8_t *buf, uint64_t len, uint64_t offset,
uint64_t *assigned_oid);
int create_and_write_sgl_osd(int fd, uint64_t pid, uint64_t requested_oid,
const uint8_t *buf, uint64_t len, uint64_t offset);
int create_and_write_vec_osd(int fd, uint64_t pid, uint64_t requested_oid,
Expand Down
4 changes: 2 additions & 2 deletions osd-initiator/tests/Makefile
Expand Up @@ -3,7 +3,7 @@
#

PROGSRC := sgio.c generic_iface_test.c iovec.c iospeed.c latency.c atomic.c \
attr-all.c iospeed-ddt.c
attr-all.c iospeed-ddt.c cli.c
PROGSRC += blk-iospeed.c sgl_test.c alignment.c alignment-rdma.c
PROGOBJ := $(PROGSRC:.c=.o)
PROGEXE := $(PROGSRC:.c=)
Expand Down Expand Up @@ -41,7 +41,7 @@ CFLAGS += -Dsg_io_v4=sg_io_v4_v2624
all:: $(LIB) $(PROGEXE) $(MPIEXE)

$(PROGEXE): %: %.o $(LIB)
$(CC) -o $@ $^ $(LIB) -lm
$(CC) -o $@ $^ $(LIB) -lm -lreadline

$(MPIEXE): %: %.o $(LIB)
$(MPICC) -o $@ $^ $(MPILIB) $(LIB) -lm
Expand Down

0 comments on commit f827899

Please sign in to comment.