Skip to content

Commit

Permalink
osd-target: Add support for PANASAS_OSD(s)
Browse files Browse the repository at this point in the history
Two Makefile configuration parameters are available:
+PANASAS_OSD=0/1
+PANASAS_OSDSIM=0/1 (Ignored if PANASAS_OSD not set)

These control two things:

* File naming convention:
  - Real OSD has objects files at "$ROOT/dfiles/$P_ID/$O_ID"
  - OSDSIM has objects files as "$ROOT/dfiles/$P_ID/$O_ID/data"

  This is set up by creating some root folder for the osd-target
  and producing a sym-link $ROOT/dfiles => /pandata in real
  HW and => /usr0/$USER/regression/$TEST/datadir/ in OSDSIM.
  This is because tgtd has other files it needs that are kept
  under $ROOT which cannot be stored at /pandata

* Will not remove any files/directories on the FORMAT command.
  osd-target is guest on the Panasas OSD and should not change
  any files. It does want to initialize attr data_base and set
  system_id on FORMAT command.

* It will attempt to create partitions/objects but will print
  an error message if so. It should not be used. This is for testing
  only.

Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
  • Loading branch information
Boaz Harrosh committed May 2, 2010
1 parent 33994cb commit 57f23a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions osd-target/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# OSD target makefile
#

#configuration flags
PANASAS_OSD=1
PANASAS_OSDSIM=1

-include ../Makedefs

SRC := attr.c db.c obj.c osd-schema.c osd.c cdb.c osd-sense.c list-entry.c
Expand All @@ -27,6 +31,14 @@ CFLAGS += -I/usr/local/include -I$(STGTDIR)/usr/bsd -I$(STGTDIR)/usr
CFLAGS += -D__MAKE_BSD_BUILD__
endif

ifeq ($(PANASAS_OSD),1)
CFLAGS += -D__PANASAS_OSD__
ifeq ($(PANASAS_OSDSIM),1)
CFLAGS += -D__PANASAS_OSDSIM__
endif
endif


LIBS += -lm -lcrypto -lsqlite3 -laio -lavahi-core -lavahi-common \
$(IB_HW_OF_LIBS) -libverbs -lrdmacm

Expand Down
34 changes: 33 additions & 1 deletion osd-target/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ static inline void get_dfile_name(char *path, const char *root,
sprintf(path, "%s/%08llx/bstreams/%.8llu/%08llx.bstream", root,
llu(pid), llu(oid % 64), llu(oid));
printf("root = %s collid = 0x%llx\n", root, llu(pid));
#elif defined (__PANASAS_OSDSIM__)
if (!oid)
sprintf(path, "%s/%s/%llu", root, dfiles, llu(pid));
else
sprintf(path, "%s/%s/%llu/%llu/data", root, dfiles,
llu(pid), llu(oid));
#elif defined (__PANASAS_OSD__)
if (!oid)
sprintf(path, "%s/%s/%llu", root, dfiles, llu(pid));
else
sprintf(path, "%s/%s/%llu/%llu", root, dfiles,
llu(pid), llu(oid));
#else
if (!oid)
sprintf(path, "%s/%s/%02x", root, dfiles,
Expand Down Expand Up @@ -1015,6 +1027,7 @@ int osd_open(const char *root, struct osd_device *osd)
goto out;
}

#ifndef __PANASAS_OSD__
/* to prevent fan-out create 256 subdirs under dfiles */
for (i = 0; i < 256; i++) {
sprintf(path, "%s/%s/%02x/", root, dfiles, i);
Expand All @@ -1024,6 +1037,7 @@ int osd_open(const char *root, struct osd_device *osd)
goto out;
}
}
#endif

/* create 'stranded-files' sub-directory */
sprintf(path, "%s/%s/", root, stranded);
Expand Down Expand Up @@ -1363,6 +1377,14 @@ static int osd_create_datafile(struct osd_device *osd, uint64_t pid,
if (ret == 0 && S_ISREG(sb.st_mode)) {
return -EEXIST;
} else if (ret == -1 && errno == ENOENT) {
#ifdef __PANASAS_OSDSIM__
char *smoog;
smoog = strrchr(path, '/');
*smoog = '\0';
create_dir(path);
osd_error("%s: panasas create %s directory %m", __func__,path);
*smoog = '/';
#endif
ret = creat(path, 0666);
if (ret <= 0)
return ret;
Expand Down Expand Up @@ -1799,6 +1821,12 @@ int osd_create_partition(struct osd_device *osd, uint64_t requested_pid,
pid = requested_pid;
}

#ifdef __PANASAS_OSD__
char path[MAXNAMELEN];
get_dfile_name(path, osd->root, pid, 0);
create_dir(path);
osd_error("%s: panasas create %s directory %m", __func__,path);
#endif
/* if pid already exists, obj_insert will fail */
ret = obj_insert(osd->dbc, pid, PARTITION_OID, PARTITION);
if (ret)
Expand Down Expand Up @@ -2092,12 +2120,14 @@ int osd_format_osd(struct osd_device *osd, uint64_t capacity, uint32_t cdb_cont_
goto out_sense;
}

#ifndef __PANASAS_OSD__
sprintf(path, "%s/%s", root, dfiles);
ret = empty_dir(path);
if (ret) {
osd_error("%s: empty_dir %s failed", __func__, path);
goto out_sense;
}
#endif

create:
ret = osd_open(root, osd); /* will create files/dirs under root */
Expand Down Expand Up @@ -2888,8 +2918,10 @@ static int contig_read(struct osd_device *osd, uint64_t pid, uint64_t oid,

get_dfile_name(path, osd->root, pid, oid);
fd = open(path, O_RDONLY|O_LARGEFILE); /* fails on non-existent obj */
if (fd < 0)
if (fd < 0) {
osd_error("%s: open faild on [%s]", __func__, path);
goto out_cdb_err;
}

readlen = pread(fd, outdata, len, offset);
ret = close(fd);
Expand Down

0 comments on commit 57f23a8

Please sign in to comment.