#include <xseg/xseg.h>
+#define TARGET_NAMELEN 128
+
static int usage(void)
{
printf("Usage: ./blockd <path_to_disk_image> [options]\n"
struct xseg_port *xport;
uint32_t portno;
int fd;
- off_t size;
+ char name[TARGET_NAMELEN];
+ uint64_t size;
struct io *ios;
struct xq free_ops;
char *free_bufs;
{
struct xseg_request *req = io->req;
- *((off_t *) req->data) = store->size;
- req->datasize = sizeof(store->size);
+ if (strcmp(req->name, store->name)) {
+ fail(store, io);
+ return;
+ }
+
+ *((uint64_t *) req->data) = store->size;
+ req->serviced = req->datasize = sizeof(store->size);
+ io->retval = io->cb.aio_offset = io->cb.aio_nbytes = req->datasize;
complete(store, io);
}
return -1;
}
+ strncpy(store->name, path, TARGET_NAMELEN);
store->fd = open(path, O_RDWR);
while (store->fd < 0) {
if (errno == ENOENT && size)
perror(path);
return r;
}
- size = stat.st_size;
+ size = (uint64_t) stat.st_size;
if (size == 0) {
fprintf(stderr, "size cannot be zero\n");
return -1;
int main(int argc, char **argv)
{
char *path, *spec = "";
- off_t size;
+ uint64_t size;
int i;
long portno;
uint32_t nr_ops;
static long sector_size = 0;
static long blksize = 512;
static int major = 0;
-static char name[XSEGBD_VOLUME_NAMELEN] = "xsegbd";
+static char name[XSEGBD_SEGMENT_NAMELEN] = "xsegbd";
static char spec[256] = "xsegdev:xsegbd:4:512:64:1024:12";
module_param(sector_size, long, 0644);
int r;
if (!xsegbd.name[0])
- strncpy(xsegbd.name, name, XSEGBD_VOLUME_NAMELEN);
+ strncpy(xsegbd.name, name, XSEGBD_SEGMENT_NAMELEN);
XSEGLOG("registering xseg types");
xsegbd.namesize = strlen(xsegbd.name);
datasize = blk_rq_bytes(blkreq);
- BUG_ON(xreq->buffersize - xsegbd.namesize < datasize);
- BUG_ON(xseg_prep_request(xreq, xsegbd.namesize, datasize));
+ BUG_ON(xreq->buffersize - xsegbd_dev->namesize < datasize);
+ BUG_ON(xseg_prep_request(xreq, xsegbd_dev->namesize, datasize));
name = XSEG_TAKE_PTR(xreq->name, xsegbd.xseg->segment);
- strncpy(name, xsegbd.name, xsegbd.namesize);
+ strncpy(name, xsegbd_dev->name, xsegbd_dev->namesize);
blkreq_idx = xq_pop_head(&xsegbd_dev->blk_queue_pending);
BUG_ON(blkreq_idx == None);
/* WARN_ON(xsebd_dev->blk_req_pending[blkreq_idx] */
struct xseg_request *xreq )
{
void *data;
+
+ if (xreq->state & XS_ERROR)
+ return -ENOENT;
+
if (!(xreq->state & XS_SERVED))
return -EIO;
datasize = sizeof(uint64_t);
BUG_ON((uint64_t)&comp < xsegbd_dev->nr_requests);
- BUG_ON(xreq->buffersize - xsegbd.namesize < datasize);
- BUG_ON(xseg_prep_request(xreq, xsegbd.namesize, datasize));
+ BUG_ON(xreq->buffersize - xsegbd_dev->namesize < datasize);
+ BUG_ON(xseg_prep_request(xreq, xsegbd_dev->namesize, datasize));
init_completion(&comp);
xreq->priv = (uint64_t)(long)∁
name = XSEG_TAKE_PTR(xreq->name, xsegbd.xseg->segment);
- strncpy(name, xsegbd.name, xsegbd.namesize);
+ strncpy(name, xsegbd_dev->name, xsegbd_dev->namesize);
xreq->size = datasize;
xreq->offset = 0;
INIT_LIST_HEAD(&xsegbd_dev->node);
/* parse cmd */
- if (sscanf(buf, "%d:%d:%d", &xsegbd_dev->src_portno, &xsegbd_dev->dst_portno, &xsegbd_dev->nr_requests) < 3) {
+ if (sscanf(buf, "%" __stringify(XSEGBD_TARGET_NAMELEN) "s "
+ "%d:%d:%d", xsegbd_dev->name, &xsegbd_dev->src_portno,
+ &xsegbd_dev->dst_portno, &xsegbd_dev->nr_requests) < 3) {
ret = -EINVAL;
goto out_dev;
}
+ xsegbd_dev->namesize = strlen(xsegbd_dev->name);
mutex_lock_nested(&xsegbd_mutex, SINGLE_DEPTH_NESTING);
#define XSEGLOG_PREFIX KERN_INFO XSEGBD_NAME ": "
#define XSEGLOG(message, args...) printk(XSEGLOG_PREFIX message "\n", ##args)
-#define XSEGBD_VOLUME_NAMELEN 32
+#define XSEGBD_SEGMENT_NAMELEN 32
+#define XSEGBD_TARGET_NAMELEN 128
#include <linux/kernel.h>
#include <linux/types.h>
#include <xq/xq.h>
struct xsegbd {
- char name[XSEGBD_VOLUME_NAMELEN];
+ char name[XSEGBD_SEGMENT_NAMELEN];
uint32_t namesize;
struct xseg_config config;
struct xseg *xseg;
struct request **blk_req_pending;
struct device dev;
struct list_head node;
+ char name[XSEGBD_TARGET_NAMELEN];
+ uint32_t namesize;
};
#endif