From 57f23a8efb7c8b9e5d243ade65e2d88a699d9e7f Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Thu, 29 Apr 2010 17:40:44 +0300 Subject: [PATCH] osd-target: Add support for PANASAS_OSD(s) 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 --- osd-target/Makefile | 12 ++++++++++++ osd-target/osd.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/osd-target/Makefile b/osd-target/Makefile index 03a47c9..4726cb1 100644 --- a/osd-target/Makefile +++ b/osd-target/Makefile @@ -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 @@ -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 diff --git a/osd-target/osd.c b/osd-target/osd.c index 2ae5a34..0c2b9e9 100644 --- a/osd-target/osd.c +++ b/osd-target/osd.c @@ -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, @@ -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); @@ -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); @@ -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; @@ -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) @@ -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 */ @@ -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);