data[dend] = 0;
fprintf(stderr,
- "%s: fd:%u, op:%u offset: %llu size: %lu retval: %lu, reqstate: %u\n"
+ "%s: fd:%u, op:%u offset: %llu size: %lu retval: %lu, reqstate: %u, serviced: %u\n"
"target[%u]: '%s', data[%llu]:\n%s------------------\n\n",
msg,
(unsigned int)io->fdcacheidx, /* this is cacheidx not fd */
(unsigned long)io->req->size,
(unsigned long)io->retval,
(unsigned int)io->req->state,
+ (unsigned long)io->req->serviced,
(unsigned int)io->req->targetlen, target,
(unsigned long long)io->req->datalen, data);
}
int i;
struct stat st;
uint32_t pathlen = strlen(path);
- char *start;
strncpy(buf, path, pathlen);
- start = strchr(target, ':');
- if (start == NULL)
- start = target;
- else
- start++;
-
for (i = 0; i < 9; i+= 3) {
- buf[pathlen + i] = start[i - (i/3)];
- buf[pathlen + i +1] = start[i + 1 - (i/3)];
+ buf[pathlen + i] = target[i - (i/3)];
+ buf[pathlen + i +1] = target[i + 1 - (i/3)];
buf[pathlen + i + 2] = '/';
if (mkdirs == 1) {
buf[pathlen + i + 3] = '\0';
if (stat(buf, &st) < 0)
- if (mkdir(buf, 0600) < 0) {
+ if (mkdir(buf, 0700) < 0) {
perror(buf);
return errno;
}
req->datalen = req->serviced;
}
else if (r == 0) {
- /* reached end of file. zero out the rest data buffer */
+ fprintf(stderr, "write returned 0\n");
memset(data + req->serviced, 0, req->datalen - req->serviced);
req->serviced = req->datalen;
}
char *data = xseg_get_data(pfiled->xseg, req);
struct xseg_request_copy *xcopy = (struct xseg_request_copy *)data;
struct stat st;
+ //FIXME is 256 enough?
char *buf = malloc(256);
int n, src, dst;
src = open(buf, O_RDWR);
if (src < 0) {
- fprintf(stderr, "fail in src\n");
+ XSEGLOG("fail in src %s\n", buf);
+ perror("open src");
fail(pfiled, io);
return;
}
return;
}
+static void handle_open(struct pfiled *pfiled, struct io *io)
+{
+ struct xseg_request *req = io->req;
+ char *buf = malloc(MAX_FILENAME_SIZE + strlen("_lock"));
+ char *pathname = malloc(MAX_PATH_SIZE + MAX_FILENAME_SIZE + strlen("_lock"));
+ int fd;
+ char *target = xseg_get_target(pfiled->xseg, req);
+
+ if (!buf || !pathname) {
+ fail(pfiled, io);
+ return;
+ }
+
+ strncpy(buf, target, req->targetlen);
+ strncpy(buf+req->targetlen, "_lock", strlen("_lock"));
+
+ if (create_path(pathname, pfiled->vpath, buf, req->targetlen + strlen("_lock"), 1) < 0) {
+ goto out_fail;
+ }
+
+ fd = open(pathname, O_CREAT | O_EXCL, S_IRWXU | S_IRUSR);
+ if (fd < 0)
+ goto out_fail;
+
+ close(fd);
+ free(buf);
+ free(pathname);
+ complete(pfiled, io);
+ return;
+
+out_fail:
+ free(buf);
+ free(pathname);
+ fail(pfiled, io);
+ return;
+}
+
+static void handle_close(struct pfiled *pfiled, struct io *io)
+{
+ struct xseg_request *req = io->req;
+ char *buf = malloc(MAX_FILENAME_SIZE + strlen("_lock"));
+ char *pathname = malloc(MAX_PATH_SIZE + MAX_FILENAME_SIZE + strlen("_lock"));
+ char *target = xseg_get_target(pfiled->xseg, req);
+
+ if (!buf || !pathname) {
+ fail(pfiled, io);
+ return;
+ }
+
+ strncpy(buf, target, req->targetlen);
+ strncpy(buf+req->targetlen, "_lock", strlen("_lock"));
+
+ if (create_path(pathname, pfiled->vpath, buf, req->targetlen + strlen("_lock"), 1) < 0) {
+ goto out_fail;
+ }
+ unlink(pathname);
+ free(buf);
+ free(pathname);
+ complete(pfiled, io);
+ return;
+
+out_fail:
+ free(buf);
+ free(pathname);
+ fail(pfiled, io);
+ return;
+}
+
static void dispatch(struct pfiled *pfiled, struct io *io)
{
if (cmdline_verbose) {
handle_copy(pfiled, io); break;
case X_DELETE:
handle_delete(pfiled, io); break;
+ case X_OPEN:
+ handle_open(pfiled, io); break;
+ case X_CLOSE:
+ handle_close(pfiled, io); break;
// case X_SNAPSHOT:
case X_SYNC:
default:
for (;;) {
accepted = NULL;
- accepted = xseg_accept(xseg, portno);
+ accepted = xseg_accept(xseg, portno, 0);
if (accepted) {
io->req = accepted;
wake_up_next_iothread(pfiled);
goto out_with_xseginit;
}
- pfiled->xport = xseg_bind_port(pfiled->xseg, cmdline_portno);
+ pfiled->xport = xseg_bind_port(pfiled->xseg, cmdline_portno, NULL);
if (!pfiled->xport) {
ret = -EIO;
perr(PE, 0, "could not bind to xseg port %ld", cmdline_portno);