Skip to content

Commit

Permalink
Merge pull request ceph#11421 from ceph/wip-jlayton-cephfs
Browse files Browse the repository at this point in the history
Small pile of random cephfs fixes and cleanup

Reviewed-by: Greg Farnum <[email protected]>
  • Loading branch information
John Spray authored Oct 17, 2016
2 parents 842a152 + e3958ef commit 371aeb5
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 197 deletions.
73 changes: 34 additions & 39 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6048,8 +6048,7 @@ int Client::get_or_create(Inode *dir, const char* name,
}

int Client::path_walk(const filepath& origpath, InodeRef *end,
const UserPerm& perms, bool followsym,
int mask, int uid, int gid)
const UserPerm& perms, bool followsym, int mask)
{
filepath path = origpath;
InodeRef cur;
Expand Down Expand Up @@ -6660,7 +6659,7 @@ int Client::setattrx(const char *relpath, struct ceph_statx *stx, int mask,

filepath path(relpath);
InodeRef in;
int r = path_walk(path, &in, perms, flags & AT_SYMLINK_NOFOLLOW);
int r = path_walk(path, &in, perms, !(flags & AT_SYMLINK_NOFOLLOW));
if (r < 0)
return r;
return _setattrx(in, stx, mask, perms);
Expand Down Expand Up @@ -6740,16 +6739,14 @@ int Client::statx(const char *relpath, struct ceph_statx *stx,

unsigned mask = statx_to_mask(flags, want);

int r = path_walk(path, &in, perms, flags & AT_SYMLINK_NOFOLLOW, mask);
int r = path_walk(path, &in, perms, !(flags & AT_SYMLINK_NOFOLLOW), mask);
if (r < 0)
return r;

if (mask && !in->caps_issued_mask(mask)) {
r = _getattr(in, mask, perms);
if (r < 0) {
ldout(cct, 3) << "statx exit on error!" << dendl;
return r;
}
r = _getattr(in, mask, perms);
if (r < 0) {
ldout(cct, 3) << "statx exit on error!" << dendl;
return r;
}

fill_statx(in, mask, stx);
Expand Down Expand Up @@ -6844,12 +6841,10 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx)
/* These are always considered to be available */
stx->stx_dev = in->snapid;
stx->stx_blksize = MAX(in->layout.stripe_unit, 4096);
stx->stx_mode = S_IFMT & in->mode;

if (use_faked_inos())
stx->stx_ino = in->faked_ino;
else
stx->stx_ino = in->ino;
/* Type bits are always set, even when CEPH_STATX_MODE is not */
stx->stx_mode = S_IFMT & in->mode;
stx->stx_ino = use_faked_inos() ? in->faked_ino : (ino_t)in->ino;
stx->stx_rdev = in->rdev;
stx->stx_mask |= (CEPH_STATX_INO|CEPH_STATX_RDEV);

Expand All @@ -6868,14 +6863,8 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx)

if (mask & CEPH_CAP_FILE_SHARED) {

if (in->ctime > in->mtime)
in->ctime.to_timespec(&stx->stx_ctime);
else
in->mtime.to_timespec(&stx->stx_ctime);

in->atime.to_timespec(&stx->stx_atime);
in->mtime.to_timespec(&stx->stx_mtime);
stx->stx_version = in->change_attr;

if (in->is_dir()) {
if (cct->_conf->client_dirsize_rbytes)
Expand All @@ -6887,9 +6876,20 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx)
stx->stx_size = in->size;
stx->stx_blocks = (in->size + 511) >> 9;
}
stx->stx_mask |= (CEPH_STATX_ATIME|CEPH_STATX_MTIME|CEPH_STATX_CTIME|
CEPH_STATX_SIZE|CEPH_STATX_BLOCKS|CEPH_STATX_VERSION);
stx->stx_mask |= (CEPH_STATX_ATIME|CEPH_STATX_MTIME|
CEPH_STATX_SIZE|CEPH_STATX_BLOCKS);
}

/* Change time and change_attr both require all shared caps to view */
if ((mask & CEPH_STAT_CAP_INODE_ALL) == CEPH_STAT_CAP_INODE_ALL) {
stx->stx_version = in->change_attr;
if (in->ctime > in->mtime)
in->ctime.to_timespec(&stx->stx_ctime);
else
in->mtime.to_timespec(&stx->stx_ctime);
stx->stx_mask |= (CEPH_STATX_CTIME|CEPH_STATX_VERSION);
}

}

void Client::touch_dn(Dentry *dn)
Expand Down Expand Up @@ -8101,7 +8101,7 @@ int Client::close(int fd)
// ------------
// read, write

loff_t Client::lseek(int fd, loff_t offset, int whence, const UserPerm& perms)
loff_t Client::lseek(int fd, loff_t offset, int whence)
{
Mutex::Locker lock(client_lock);
tout(cct) << "lseek" << std::endl;
Expand All @@ -8116,18 +8116,14 @@ loff_t Client::lseek(int fd, loff_t offset, int whence, const UserPerm& perms)
if (f->flags & O_PATH)
return -EBADF;
#endif
return _lseek(f, offset, whence, perms);
return _lseek(f, offset, whence);
}

loff_t Client::_lseek(Fh *f, loff_t offset, int whence, const UserPerm& perms)
loff_t Client::_lseek(Fh *f, loff_t offset, int whence)
{
Inode *in = f->inode.get();
int r;

if (!may_open(f->inode.get(), f->flags, perms)) {
return -EPERM;
}

switch (whence) {
case SEEK_SET:
f->pos = offset;
Expand All @@ -8138,7 +8134,7 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence, const UserPerm& perms)
break;

case SEEK_END:
r = _getattr(in, CEPH_STAT_CAP_SIZE, perms);
r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms);
if (r < 0)
return r;
f->pos = in->size + offset;
Expand Down Expand Up @@ -8685,7 +8681,7 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
* change out from under us.
*/
if (f->flags & O_APPEND) {
int r = _lseek(f, 0, SEEK_END, f->actor_perms);
int r = _lseek(f, 0, SEEK_END);
if (r < 0) {
unlock_fh_pos(f);
return r;
Expand Down Expand Up @@ -9904,7 +9900,7 @@ Inode *Client::ll_get_inode(vinodeno_t vino)
return in;
}

int Client::_ll_getattr(Inode *in, const UserPerm& perms)
int Client::_ll_getattr(Inode *in, int caps, const UserPerm& perms)
{
vinodeno_t vino = _get_vino(in);

Expand All @@ -9915,14 +9911,14 @@ int Client::_ll_getattr(Inode *in, const UserPerm& perms)
if (vino.snapid < CEPH_NOSNAP)
return 0;
else
return _getattr(in, CEPH_STAT_CAP_INODE_ALL, perms);
return _getattr(in, caps, perms);
}

int Client::ll_getattr(Inode *in, struct stat *attr, const UserPerm& perms)
{
Mutex::Locker lock(client_lock);

int res = _ll_getattr(in, perms);
int res = _ll_getattr(in, CEPH_STAT_CAP_INODE_ALL, perms);

if (res == 0)
fill_stat(in, attr);
Expand All @@ -9939,7 +9935,7 @@ int Client::ll_getattrx(Inode *in, struct ceph_statx *stx, unsigned int want,
unsigned mask = statx_to_mask(flags, want);

if (mask && !in->caps_issued_mask(mask))
res = _ll_getattr(in, perms);
res = _ll_getattr(in, mask, perms);

if (res == 0)
fill_statx(in, mask, stx);
Expand Down Expand Up @@ -11705,15 +11701,14 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,
return r;
}

loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence,
const UserPerm& perms)
loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence)
{
Mutex::Locker lock(client_lock);
tout(cct) << "ll_lseek" << std::endl;
tout(cct) << offset << std::endl;
tout(cct) << whence << std::endl;

return _lseek(fh, offset, whence, perms);
return _lseek(fh, offset, whence);
}

int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl)
Expand Down
9 changes: 4 additions & 5 deletions src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class Client : public Dispatcher, public md_config_obs_t {
// path traversal for high-level interface
InodeRef cwd;
int path_walk(const filepath& fp, InodeRef *end, const UserPerm& perms,
bool followsym=true, int mask=0, int uid=-1, int gid=-1);
bool followsym=true, int mask=0);

int fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0);
int fill_stat(InodeRef& in, struct stat *st, frag_info_t *dirstat=0, nest_info_t *rstat=0) {
Expand Down Expand Up @@ -809,7 +809,6 @@ class Client : public Dispatcher, public md_config_obs_t {
const char *data_pool, bool *created, const UserPerm &perms);

loff_t _lseek(Fh *fh, loff_t offset, int whence);
loff_t _lseek(Fh *fh, loff_t offset, int whence, const UserPerm& perms);
int _read(Fh *fh, int64_t offset, uint64_t size, bufferlist *bl);
int _write(Fh *fh, int64_t offset, uint64_t size, const char *buf,
const struct iovec *iov, int iovcnt);
Expand Down Expand Up @@ -921,7 +920,7 @@ class Client : public Dispatcher, public md_config_obs_t {

mds_rank_t _get_random_up_mds() const;

int _ll_getattr(Inode *in, const UserPerm& perms);
int _ll_getattr(Inode *in, int caps, const UserPerm& perms);

public:
int mount(const std::string &mount_root, const UserPerm& perms,
Expand Down Expand Up @@ -1033,7 +1032,7 @@ class Client : public Dispatcher, public md_config_obs_t {
int lookup_parent(Inode *in, const UserPerm& perms, Inode **parent=NULL);
int lookup_name(Inode *in, Inode *parent, const UserPerm& perms);
int close(int fd);
loff_t lseek(int fd, loff_t offset, int whence, const UserPerm& perms);
loff_t lseek(int fd, loff_t offset, int whence);
int read(int fd, char *buf, loff_t size, loff_t offset=-1);
int preadv(int fd, const struct iovec *iov, int iovcnt, loff_t offset=-1);
int write(int fd, const char *buf, loff_t size, loff_t offset=-1);
Expand Down Expand Up @@ -1168,7 +1167,7 @@ class Client : public Dispatcher, public md_config_obs_t {

int ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl);
int ll_write(Fh *fh, loff_t off, loff_t len, const char *data);
loff_t ll_lseek(Fh *fh, loff_t offset, int whence, const UserPerm& perms);
loff_t ll_lseek(Fh *fh, loff_t offset, int whence);
int ll_flush(Fh *fh);
int ll_fsync(Fh *fh, bool syncdataonly);
int ll_fallocate(Fh *fh, int mode, loff_t offset, loff_t length);
Expand Down
2 changes: 1 addition & 1 deletion src/client/SyntheticClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
int fd = open_files[f];
int64_t off = t.get_int();
int64_t whence = t.get_int();
client->lseek(fd, off, whence, perms);
client->lseek(fd, off, whence);
} else if (strcmp(op, "read") == 0) {
int64_t f = t.get_int();
int64_t size = t.get_int();
Expand Down
10 changes: 5 additions & 5 deletions src/client/hypertable/CephBroker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,19 @@ void CephBroker::remove(ResponseCallback *cb, const char *fname) {

void CephBroker::length(ResponseCallbackLength *cb, const char *fname, bool) {
int r;
struct stat statbuf;
struct ceph_statx stx;

HT_DEBUGF("length file='%s'", fname);

if ((r = ceph_lstat(cmount, fname, &statbuf)) < 0) {
if ((r = ceph_statx(cmount, fname, &stx, CEPH_STATX_SIZE, AT_SYMLINK_NOFOLLOW)) < 0) {
String abspath;
make_abs_path(fname, abspath);
std::string errs(cpp_strerror(r));
HT_ERRORF("length (stat) failed: file='%s' - %s", abspath.c_str(), errs.c_str());
report_error(cb,- r);
return;
}
cb->response(statbuf.st_size);
cb->response(stx.stx_size);
}

void CephBroker::pread(ResponseCallbackRead *cb, uint32_t fd, uint64_t offset,
Expand Down Expand Up @@ -487,11 +487,11 @@ void CephBroker::readdir(ResponseCallbackReaddir *cb, const char *dname) {

void CephBroker::exists(ResponseCallbackExists *cb, const char *fname) {
String abspath;
struct stat statbuf;
struct ceph_statx stx;

HT_DEBUGF("exists file='%s'", fname);
make_abs_path(fname, abspath);
cb->response(ceph_lstat(cmount, abspath.c_str(), &statbuf) == 0);
cb->response(ceph_statx(cmount, abspath.c_str(), &stx, 0, AT_SYMLINK_NOFOLLOW) == 0);
}

void CephBroker::rename(ResponseCallback *cb, const char *src, const char *dst) {
Expand Down
Loading

0 comments on commit 371aeb5

Please sign in to comment.