CephBroker::CephBroker(PropertiesPtr& cfg) {
m_verbose = cfg->get_bool("Hypertable.Verbose");
-
+ m_root_dir = "";
//construct an arguments array
const char *argv[9];
String zero = "cephBroker";
argv[1] = one.c_str();
argv[2] = (cfg->get_str("CephBroker.MonAddr").c_str());
argv[3] = "--debug_client";
- argv[4] = "20";
+ argv[4] = "10";
argv[5] = "--debug_ms";
argv[6] = "1";
argv[7] = "--lockdep";
fd = atomic_inc_return(&ms_next_fd);
if ((ceph_fd = ceph_open(abspath.c_str(), O_RDONLY)) < 0) {
- report_error(cb, ceph_fd);
+ report_error(cb, -ceph_fd);
return;
}
HT_INFOF("open (%s) fd=%d ceph_fd=%d", fname, fd, ceph_fd);
int flags;
String abspath;
+ make_abs_path(fname, abspath);
HT_DEBUGF("create file='%s' overwrite=%d bufsz=%d replication=%d blksz=%lld",
fname, (int)overwrite, bufsz, (int)replication, (Lld)blksz);
else
flags = O_WRONLY | O_CREAT | O_APPEND;
- if ((ceph_fd = ceph_open(abspath.c_str(), flags, 0644)) < 0) {
- HT_ERRORF("open failed: file=%s - %s", abspath.c_str(), strerror(errno));
+ if ((ceph_fd = ceph_open(abspath.c_str(), flags, O_CREAT)) < 0) {
+ HT_ERRORF("open failed: file=%s - %s", abspath.c_str(), strerror(-ceph_fd));
report_error(cb, ceph_fd);
return;
}
}
if((offset = ceph_lseek(fdata->fd, 0, SEEK_CUR)) < 0) {
- HT_ERRORF("lseek failed: fd=%d ceph_fd=%d offset=0 SEEK_CUR - %s", fd, fdata->fd, strerror(errno));
+ HT_ERRORF("lseek failed: fd=%d ceph_fd=%d offset=0 SEEK_CUR - %s", fd, fdata->fd, strerror(-offset));
report_error(cb, offset);
return;
}
if ((nread=ceph_read(fdata->fd, (char *)buf.base, amount)) < 0 ) {
HT_ERRORF("read failed: fd=%d ceph_fd=%d amount=%d", fd, fdata->fd, amount);
- report_error(cb, nread);
+ report_error(cb, -nread);
return;
}
if ((offset = (uint64_t)ceph_lseek(fdata->fd, 0, SEEK_CUR)) < 0) {
HT_ERRORF("lseek failed: fd=%d ceph_fd=%d offset=0 SEEK_CUR - %s", fd, fdata->fd,
- strerror(errno));
+ strerror(-offset));
report_error(cb, offset);
return;
}
if ((nwritten = ceph_write(fdata->fd, (const char *)data, amount)) < 0) {
HT_ERRORF("write failed: fd=%d ceph_fd=%d amount=%d - %s", fd, fdata->fd, amount,
- strerror(errno));
- report_error(cb, nwritten);
+ strerror(-nwritten));
+ report_error(cb, -nwritten);
return;
}
cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}
-
- if ((offset = (uint64_t)ceph_lseek(fdata->fd, offset, SEEK_SET)) < 0) {
- HT_ERRORF("lseek failed: fd=%d ceph_fd=%d offset=%llu - %s", fd, fdata->fd, (Llu)offset,
- strerror(errno));
+ int r;
+ if ((r = (uint64_t)ceph_lseek(fdata->fd, offset, SEEK_SET)) < 0) {
+ HT_ERRORF("lseek failed: fd=%d ceph_fd=%d offset=%llu - %s", fd, fdata->fd,
+ (Llu)offset, strerror(-r));
report_error(cb, offset);
return;
}
int r;
if((r=ceph_unlink(abspath.c_str())) < 0) {
- HT_ERRORF("unlink failed: file='%s' - %s", abspath.c_str(), strerror(errno));
+ HT_ERRORF("unlink failed: file='%s' - %s", abspath.c_str(), strerror(-r));
report_error(cb, r);
return;
}
}
void CephBroker::length(ResponseCallbackLength *cb, const char *fname){
- int res;
+ int r;
struct stat statbuf;
HT_DEBUGF("length file='%s'", fname);
- if ((res = ceph_lstat(fname, &statbuf)) < 0) {
+ if ((r = ceph_lstat(fname, &statbuf)) < 0) {
String abspath;
make_abs_path(fname, abspath);
- HT_ERRORF("length (stat) failed: file='%s' - %s", abspath.c_str(), strerror(errno));
- report_error(cb, res);
+ HT_ERRORF("length (stat) failed: file='%s' - %s", abspath.c_str(), strerror(-r));
+ report_error(cb,- r);
return;
}
cb->response(statbuf.st_size);
if ((nread = ceph_read(fdata->fd, (char *)buf.base, amount, offset)) < 0) {
HT_ERRORF("pread failed: fd=%d ceph_fd=%d amount=%d offset=%llu - %s", fd, fdata->fd,
- amount, (Llu)offset, strerror(errno));
+ amount, (Llu)offset, strerror(-nread));
report_error(cb, nread);
return;
}
make_abs_path(dname, absdir);
int r;
- if((r=ceph_mkdirs(absdir.c_str(), 0644)) < 0) {
- HT_ERRORF("mkdirs failed: dname='%s' - %d", absdir.c_str(), r);
- report_error(cb, r);
+ if((r=ceph_mkdirs(absdir.c_str(), 0644)) < 0 && r!=-EEXIST) {
+ HT_ERRORF("mkdirs failed: dname='%s' - %d", absdir.c_str(), -r);
+ report_error(cb, -r);
return;
}
cb->response_ok();
int r;
if((r=ceph_rmdir(absdir.c_str())) < 0) {
HT_ERRORF("failed to remove dir %s", absdir.c_str());
- report_error(cb, r);
+ report_error(cb, -r);
return;
}
int r;
if((r=ceph_fsync(fdata->fd, true)) != 0) {
- HT_ERRORF("flush failed: fd=%d ceph_fd=%d - %s", fd, fdata->fd, strerror(errno));
- report_error(cb, r);
+ HT_ERRORF("flush failed: fd=%d ceph_fd=%d - %s", fd, fdata->fd, strerror(-r));
+ report_error(cb, -r);
return;
}