/****** file i/o **********/
-int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit,
- int stripe_count, int object_size, const char *data_pool)
+int Client::open(const char *relpath, int flags, const UserPerm& perms,
+ mode_t mode, int stripe_unit, int stripe_count,
+ int object_size, const char *data_pool)
{
ldout(cct, 3) << "open enter(" << relpath << ", " << flags << "," << mode << ") = " << dendl;
Mutex::Locker lock(client_lock);
tout(cct) << relpath << std::endl;
tout(cct) << flags << std::endl;
- uid_t uid = get_uid();
- gid_t gid = get_gid();
-
Fh *fh = NULL;
#if defined(__linux__) && defined(O_PATH)
bool created = false;
/* O_CREATE with O_EXCL enforces O_NOFOLLOW. */
bool followsym = !((flags & O_NOFOLLOW) || ((flags & O_CREAT) && (flags & O_EXCL)));
- int r = path_walk(path, &in, followsym, uid, gid);
+ int r = path_walk(path, &in, perms, followsym);
if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL))
return -EEXIST;
string dname = dirpath.last_dentry();
dirpath.pop_dentry();
InodeRef dir;
- r = path_walk(dirpath, &dir, true, uid, gid);
+ r = path_walk(dirpath, &dir, perms, true);
if (r < 0)
goto out;
if (cct->_conf->client_permissions) {
- r = may_create(dir.get(), uid, gid);
+ r = may_create(dir.get(), perms);
if (r < 0)
goto out;
}
r = _create(dir.get(), dname.c_str(), flags, mode, &in, &fh, stripe_unit,
- stripe_count, object_size, data_pool, &created, uid, gid);
+ stripe_count, object_size, data_pool, &created, perms);
}
if (r < 0)
goto out;
if (!created) {
// posix says we can only check permissions of existing files
if (cct->_conf->client_permissions) {
- r = may_open(in.get(), flags, uid, gid);
+ r = may_open(in.get(), flags, perms);
if (r < 0)
goto out;
}
}
if (!fh)
- r = _open(in.get(), flags, mode, &fh, uid, gid);
+ r = _open(in.get(), flags, mode, &fh, perms);
if (r >= 0) {
// allocate a integer file descriptor
assert(fh);
return r;
}
-int Client::open(const char *relpath, int flags, mode_t mode)
+int Client::open(const char *relpath, int flags, const UserPerm& perms, mode_t mode)
{
/* Use default file striping parameters */
- return open(relpath, flags, mode, 0, 0, 0, NULL);
+ return open(relpath, flags, perms, mode, 0, 0, 0, NULL);
}
int Client::lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name,
int _removexattr(InodeRef &in, const char *nm, const UserPerm& perms);
int _open(Inode *in, int flags, mode_t mode, Fh **fhp,
const UserPerm& perms);
- int _open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid) {
- UserPerm perms(uid, gid);
- return _open(in, flags, mode, fhp, perms);
- }
int _renew_caps(Inode *in);
int _create(Inode *in, const char *name, int flags, mode_t mode, InodeRef *inp,
Fh **fhp, int stripe_unit, int stripe_count, int object_size,
// file ops
int mknod(const char *path, mode_t mode, dev_t rdev=0);
- int open(const char *path, int flags, mode_t mode=0);
- int open(const char *path, int flags, mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool);
+ int open(const char *path, int flags, const UserPerm& perms, mode_t mode=0);
+ int open(const char *path, int flags, const UserPerm& perms,
+ mode_t mode, int stripe_unit, int stripe_count, int object_size,
+ const char *data_pool);
int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name,
const UserPerm& perms);
int lookup_ino(inodeno_t ino, const UserPerm& perms, Inode **inode=NULL);
int count = iargs.front(); iargs.pop_front();
if (run_me()) {
for (int i=0; i<count; i++) {
- int fd = client->open("test", (rand()%2) ? (O_WRONLY|O_CREAT) : O_RDONLY);
+ int fd = client->open("test", (rand()%2) ?
+ (O_WRONLY|O_CREAT) : O_RDONLY,
+ perms);
if (fd > 0) client->close(fd);
}
}
int64_t b = t.get_int();
int64_t c = t.get_int();
int64_t d = t.get_int();
- int64_t fd = client->open(a, b, c);
+ int64_t fd = client->open(a, b, perms, c);
if (fd > 0) open_files[d] = fd;
} else if (strcmp(op, "oldopen") == 0) {
const char *a = t.get_string(buf, p);
int64_t b = t.get_int();
int64_t d = t.get_int();
- int64_t fd = client->open(a, b, 0755);
+ int64_t fd = client->open(a, b, perms, 0755);
if (fd > 0) open_files[d] = fd;
} else if (strcmp(op, "close") == 0) {
int64_t id = t.get_int();
UserPerm perms = client->pick_my_perms();
// open file
- int fd = client->open(fn.c_str(), O_RDONLY);
+ int fd = client->open(fn.c_str(), O_RDONLY, perms);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
if (fd < 0) return fd;
if (more) {
client->lstat(d, &st, perms);
- int fd = client->open(d, O_RDONLY);
+ int fd = client->open(d, O_RDONLY, perms);
client->unlink(d, perms);
client->close(fd);
}
list<int> fds;
for (int n=0; n<num; n++) {
snprintf(d, sizeof(d), "test/file.%d", n);
- int fd = client->open(d,O_RDONLY);
+ int fd = client->open(d, O_RDONLY, perms);
if (fd > 0) fds.push_back(fd);
}
// Hits OSD 0 with writes to various files with OSD 0 as the primary.
int SyntheticClient::overload_osd_0(int n, int size, int wrsize) {
-
+ UserPerm perms = client->pick_my_perms();
// collect a bunch of files starting on OSD 0
int left = n;
int tried = 0;
dout(0) << "in OSD overload" << dendl;
string filename = get_sarg(tried);
dout(1) << "OSD Overload workload: trying file " << filename << dendl;
- int fd = client->open(filename.c_str(), O_RDWR|O_CREAT);
+ int fd = client->open(filename.c_str(), O_RDWR|O_CREAT, perms);
++tried;
// only use the file if its first primary is OSD 0
char *buf = new char[wrsize+100]; // 1 MB
memset(buf, 7, wrsize);
int64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)wrsize;
+ UserPerm perms = client->pick_my_perms();
- int fd = client->open(fn.c_str(), O_RDWR|O_CREAT);
+ int fd = client->open(fn.c_str(), O_RDWR|O_CREAT, perms);
dout(5) << "writing to " << fn << " fd " << fd << dendl;
if (fd < 0) {
delete[] buf;
char *buf = new char[rdsize];
memset(buf, 1, rdsize);
uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize;
+ UserPerm perms = client->pick_my_perms();
- int fd = client->open(fn.c_str(), O_RDONLY);
+ int fd = client->open(fn.c_str(), O_RDONLY, perms);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
if (fd < 0) {
delete[] buf;
int SyntheticClient::read_random(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes
{
+ UserPerm perms = client->pick_my_perms();
uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize;
- int fd = client->open(fn.c_str(), O_RDWR);
+ int fd = client->open(fn.c_str(), O_RDWR, perms);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
if (fd < 0) return fd;
int SyntheticClient::read_random_ex(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes
{
uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize;
- int fd = client->open(fn.c_str(), O_RDWR);
+ UserPerm perms = client->pick_my_perms();
+ int fd = client->open(fn.c_str(), O_RDWR, perms);
dout(5) << "reading from " << fn << " fd " << fd << dendl;
if (fd < 0) return fd;
if (contents.empty())
op = CEPH_MDS_OP_READDIR;
else {
- r = client->open( get_random_sub(), O_RDONLY );
+ r = client->open(get_random_sub(), O_RDONLY, perms);
if (r > 0) {
assert(open_files.count(r) == 0);
open_files.insert(r);
const char *fn = "blah";
char buffer[8192];
client->unlink(fn, perms);
- int handle = client->open(fn,O_CREAT|O_RDWR,S_IRWXU);
+ int handle = client->open(fn, O_CREAT|O_RDWR, perms, S_IRWXU);
assert(handle>=0);
int r=client->write(handle,buffer,8192);
assert(r>=0);
r=client->close(handle);
assert(r>=0);
- handle = client->open(fn,O_RDWR); // open the same file, it must have some data already
+ handle = client->open(fn, O_RDWR, perms); // open the same file, it must have some data already
assert(handle>=0);
r=client->read(handle,buffer,8192);
assert(r==8192); // THIS ASSERTION FAILS with disabled cache
}
if (1) {
dout(0) << "first" << dendl;
- int fd = client->open("tester", O_WRONLY|O_CREAT);
+ int fd = client->open("tester", O_WRONLY|O_CREAT, perms);
client->write(fd, "hi there", 0, 8);
client->close(fd);
dout(0) << "sleep" << dendl;
sleep(10);
dout(0) << "again" << dendl;
- fd = client->open("tester", O_WRONLY|O_CREAT);
+ fd = client->open("tester", O_WRONLY|O_CREAT, perms);
client->write(fd, "hi there", 0, 8);
client->close(fd);
return;
char src[80];
snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
//int fd =
- client->open(src, O_RDONLY);
+ client->open(src, O_RDONLY, perms);
}
return;
if (S_ISDIR(mode)) {
client->mkdir(f.c_str(), mode, perms);
} else {
- int fd = client->open(f.c_str(), O_WRONLY|O_CREAT, mode & 0777);
+ int fd = client->open(f.c_str(), O_WRONLY|O_CREAT, perms, mode & 0777);
assert(fd > 0);
if (data) {
client->write(fd, "", 0, size);
int SyntheticClient::chunk_file(string &filename)
{
- int fd = client->open(filename.c_str(), O_RDONLY);
+ UserPerm perms = client->pick_my_perms();
+ int fd = client->open(filename.c_str(), O_RDONLY, perms);
if (fd < 0)
return fd;
struct stat st;
- UserPerm perms = client->pick_my_perms();
int ret = client->fstat(fd, &st, perms);
if (ret < 0) {
client->close(fd);
string f = dir;
f += "/foo";
- int fd = client->open(f.c_str(), O_WRONLY|O_CREAT|O_TRUNC);
+ int fd = client->open(f.c_str(), O_WRONLY|O_CREAT|O_TRUNC, perms);
char buf[1048576*4];
client->write(fd, buf, sizeof(buf), 0);
s += "/.snap/1";
client->mkdir(s.c_str(), 0755, perms);
- fd = client->open(f.c_str(), O_WRONLY);
+ fd = client->open(f.c_str(), O_WRONLY, perms);
client->write(fd, buf, 1048576*2, 1048576);
client->fsync(fd, true);
client->close(fd);