req->head.args.open.flags = flags;
req->head.args.open.mode = mode;
- int cmode = file_flags_to_mode(flags);
+ int cmode = ceph_flags_to_mode(flags);
// FIXME where does FUSE maintain user information
req->set_caller_uid(getuid());
movepos = true;
}
- bool lazy = f->mode == FILE_MODE_LAZY;
+ bool lazy = f->mode == CEPH_FILE_MODE_LAZY;
// wait for RD cap and/or a valid file size
while (1) {
unlock_fh_pos(f);
}
- bool lazy = f->mode == FILE_MODE_LAZY;
+ bool lazy = f->mode == CEPH_FILE_MODE_LAZY;
dout(10) << "cur file size is " << in->inode.size << dendl;
Fh *f = fd_map[fd];
Inode *in = f->inode;
- if (f->mode & FILE_MODE_LAZY) {
+ if (f->mode & CEPH_FILE_MODE_LAZY) {
// wait for lazy cap
while ((in->file_caps() & CEPH_CAP_LAZYIO) == 0) {
dout(7) << " don't have lazy cap, waiting" << dendl;
Fh *f = fd_map[fd];
Inode *in = f->inode;
- if (f->mode & FILE_MODE_LAZY) {
+ if (f->mode & CEPH_FILE_MODE_LAZY) {
// wait for lazy cap
while ((in->file_caps() & CEPH_CAP_LAZYIO) == 0) {
dout(7) << " don't have lazy cap, waiting" << dendl;
}
void add_open(int cmode) {
- if (cmode & FILE_MODE_R) num_open_rd++;
- if (cmode & FILE_MODE_W) num_open_wr++;
- if (cmode & FILE_MODE_LAZY) num_open_lazy++;
+ if (cmode & CEPH_FILE_MODE_RD) num_open_rd++;
+ if (cmode & CEPH_FILE_MODE_WR) num_open_wr++;
+ if (cmode & CEPH_FILE_MODE_LAZY) num_open_lazy++;
}
void sub_open(int cmode) {
- if (cmode & FILE_MODE_R) num_open_rd--;
- if (cmode & FILE_MODE_W) num_open_wr--;
- if (cmode & FILE_MODE_LAZY) num_open_lazy--;
+ if (cmode & CEPH_FILE_MODE_RD) num_open_rd--;
+ if (cmode & CEPH_FILE_MODE_WR) num_open_wr--;
+ if (cmode & CEPH_FILE_MODE_LAZY) num_open_lazy--;
}
int authority(const string& dname) {
#ifdef __KERNEL__
# include <linux/in.h>
# include <linux/types.h>
+# include <asm/fcntl.h>
#else
# include <netinet/in.h>
# include "inttypes.h"
# include "byteorder.h"
+# include <fcntl.h>
#endif
#define CEPH_MON_PORT 12345
__u32 dist[];
} __attribute__ ((packed));
+/* file access modes */
+#define CEPH_FILE_MODE_PIN 0
+#define CEPH_FILE_MODE_RD 1
+#define CEPH_FILE_MODE_WR 2
+#define CEPH_FILE_MODE_RDWR 3 /* RD | WR */
+#define CEPH_FILE_MODE_LAZY 4
+#define CEPH_FILE_MODE_NUM 8 /* bc these are bit fields.. mostly */
+
+static inline int ceph_flags_to_mode(int flags)
+{
+ if ((flags & O_DIRECTORY) == O_DIRECTORY)
+ return CEPH_FILE_MODE_PIN;
+#ifdef O_LAZY
+ if (flags & O_LAZY)
+ return CEPH_FILE_MODE_LAZY;
+#endif
+ if ((flags & O_APPEND) == O_APPEND)
+ flags |= O_WRONLY;
+
+ flags &= O_ACCMODE;
+ if ((flags & O_RDWR) == O_RDWR)
+ return CEPH_FILE_MODE_RDWR;
+ if ((flags & O_WRONLY) == O_WRONLY)
+ return CEPH_FILE_MODE_WR;
+ return CEPH_FILE_MODE_RD;
+}
+
/* client file caps */
#define CEPH_CAP_PIN 1 /* no specific capabilities beyond the pin */
#define CEPH_CAP_RDCACHE 2 /* client can cache reads */
#define CEPH_CAP_LAZYIO 64 /* client can perform lazy io */
#define CEPH_CAP_EXCL 128 /* exclusive/loner access */
+static inline int ceph_caps_for_mode(int mode)
+{
+ switch (mode) {
+ case CEPH_FILE_MODE_PIN:
+ return CEPH_CAP_PIN;
+ case CEPH_FILE_MODE_RD:
+ return CEPH_CAP_PIN |
+ CEPH_CAP_RD | CEPH_CAP_RDCACHE;
+ case CEPH_FILE_MODE_RDWR:
+ return CEPH_CAP_PIN |
+ CEPH_CAP_RD | CEPH_CAP_RDCACHE |
+ CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
+ CEPH_CAP_EXCL;
+ case CEPH_FILE_MODE_WR:
+ return CEPH_CAP_PIN |
+ CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
+ CEPH_CAP_EXCL;
+ }
+ return 0;
+}
+
enum {
CEPH_CAP_OP_GRANT, /* mds->client grant */
CEPH_CAP_OP_ACK, /* client->mds ack (if prior grant was a recall) */
}
-// these are bit masks
-#define FILE_MODE_R 1
-#define FILE_MODE_W 2
-#define FILE_MODE_RW (1|2)
-#define FILE_MODE_LAZY 4
-#define FILE_MODE_PIN 8
-
-static inline int file_flags_to_mode(int flags) {
- if (flags & O_DIRECTORY)
- return FILE_MODE_PIN;
- if (flags & O_LAZY)
- return FILE_MODE_LAZY;
- if (flags & O_WRONLY)
- return FILE_MODE_W;
- if (flags & O_RDWR)
- return FILE_MODE_RW;
- if (flags & O_APPEND)
- return FILE_MODE_W;
- return FILE_MODE_R;
-}
static inline bool file_mode_is_readonly(int mode) {
- return (mode & FILE_MODE_W) == 0;
+ return (mode & CEPH_FILE_MODE_WR) == 0;
}
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_OPEN, pathbase, path,
0, 0);
req->r_expects_cap = 1;
- req->r_fmode = ceph_file_mode(flags);
+ req->r_fmode = ceph_flags_to_mode(flags);
kfree(path);
if (!IS_ERR(req)) {
rhead = req->r_request->front.iov_base;
if (S_ISDIR(inode->i_mode))
flags = O_DIRECTORY;
- fmode = ceph_file_mode(flags);
+ fmode = ceph_flags_to_mode(flags);
wantcaps = ceph_caps_for_mode(fmode);
dout(5, "open inode %p ino %llx file %p\n", inode,
dout(10, "__ceph_remove_cap %p from %p\n", cap, &cap->ci->vfs_inode);
/* remove from session list */
- list_del(&cap->session_caps);
+ list_del_init(&cap->session_caps);
session->s_nr_caps--;
/* remove from inode list */
- list_del(&cap->ci_caps);
+ list_del_init(&cap->ci_caps);
cap->session = 0;
cap->mds = -1; /* mark unused */
INIT_LIST_HEAD(&ci->i_caps);
for (i = 0; i < STATIC_CAPS; i++)
ci->i_static_caps[i].mds = -1;
- for (i = 0; i < 4; i++)
+ for (i = 0; i < CEPH_FILE_MODE_NUM; i++)
ci->i_nr_by_mode[i] = 0;
init_waitqueue_head(&ci->i_cap_wq);
#define STATIC_CAPS 2
-enum {
- FILE_MODE_PIN,
- FILE_MODE_RDONLY,
- FILE_MODE_RDWR,
- FILE_MODE_WRONLY
-};
struct ceph_inode_info {
u64 i_ceph_ino;
wait_queue_head_t i_cap_wq;
unsigned long i_hold_caps_until; /* jiffies */
- int i_nr_by_mode[4];
+ int i_nr_by_mode[CEPH_FILE_MODE_NUM];
loff_t i_max_size; /* size authorized by mds */
loff_t i_reported_size; /* (max_)size reported to or requested of mds */
loff_t i_wanted_max_size; /* offset we'd like to write too */
return used;
}
-static inline int ceph_caps_for_mode(int mode)
-{
- switch (mode) {
- case FILE_MODE_PIN:
- return CEPH_CAP_PIN;
- case FILE_MODE_RDONLY:
- return CEPH_CAP_PIN |
- CEPH_CAP_RD | CEPH_CAP_RDCACHE;
- case FILE_MODE_RDWR:
- return CEPH_CAP_PIN |
- CEPH_CAP_RD | CEPH_CAP_RDCACHE |
- CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
- CEPH_CAP_EXCL;
- case FILE_MODE_WRONLY:
- return CEPH_CAP_PIN |
- CEPH_CAP_WR | CEPH_CAP_WRBUFFER |
- CEPH_CAP_EXCL;
- }
- return 0;
-}
-
static inline int __ceph_caps_file_wanted(struct ceph_inode_info *ci)
{
int want = 0;
return w;
}
-static inline int ceph_file_mode(int flags)
-{
- if ((flags & O_DIRECTORY) == O_DIRECTORY)
- return FILE_MODE_PIN;
- if ((flags & O_ACCMODE) == O_RDWR)
- return FILE_MODE_RDWR;
- if ((flags & O_ACCMODE) == O_WRONLY)
- return FILE_MODE_WRONLY;
- if ((flags & O_ACCMODE) == O_RDONLY)
- return FILE_MODE_RDONLY;
- return FILE_MODE_RDWR; /* not -EINVAL under Linux, strangely */
-}
-
static inline void __ceph_get_fmode(struct ceph_inode_info *ci, int mode)
{
ci->i_nr_by_mode[mode]++;
// my needs
assert(session->inst.name.is_client());
int my_client = session->inst.name.num();
- int my_want = 0;
- if (mode & FILE_MODE_PIN) my_want |= CEPH_CAP_PIN;
- if (mode & FILE_MODE_R) my_want |= CEPH_CAP_RDCACHE | CEPH_CAP_RD;
- if (mode & FILE_MODE_W) my_want |= CEPH_CAP_WRBUFFER | CEPH_CAP_WR | CEPH_CAP_EXCL;
+ int my_want = ceph_caps_for_mode(mode);
// register a capability
Capability *cap = in->get_client_cap(my_client);
MClientRequest *req = mdr->client_request;
int flags = req->head.args.open.flags;
- int cmode = file_flags_to_mode(req->head.args.open.flags);
+ int cmode = ceph_flags_to_mode(req->head.args.open.flags);
bool need_auth = !file_mode_is_readonly(cmode) || (flags & O_TRUNC);
if (!cur) return;
// can only open a dir with mode FILE_MODE_PIN, at least for now.
- if (cur->inode.is_dir()) cmode = FILE_MODE_PIN;
+ if (cur->inode.is_dir()) cmode = CEPH_FILE_MODE_PIN;
dout(10) << "open flags = " << flags
<< ", filemode = " << cmode
void Server::_do_open(MDRequest *mdr, CInode *cur)
{
MClientRequest *req = mdr->client_request;
- int cmode = file_flags_to_mode(req->head.args.open.flags);
- if (cur->inode.is_dir()) cmode = FILE_MODE_PIN;
+ int cmode = ceph_flags_to_mode(req->head.args.open.flags);
+ if (cur->inode.is_dir()) cmode = CEPH_FILE_MODE_PIN;
// register new cap
Capability *cap = mds->locker->issue_new_caps(cur, cmode, mdr->session);
// hit pop
mdr->now = g_clock.now();
- if (cmode == FILE_MODE_RW ||
- cmode == FILE_MODE_W)
+ if (cmode == CEPH_FILE_MODE_RDWR ||
+ cmode == CEPH_FILE_MODE_WR)
mds->balancer->hit_inode(mdr->now, cur, META_POP_IWR);
else
mds->balancer->hit_inode(mdr->now, cur, META_POP_IRD,
}
bool open_file_mode_is_readonly() {
- return file_mode_is_readonly(file_flags_to_mode(head.args.open.flags));
+ return file_mode_is_readonly(ceph_flags_to_mode(head.args.open.flags));
}
bool is_idempotent() {
if (head.op == CEPH_MDS_OP_OPEN)