aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph/ceph_fs.c
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2009-10-06 14:31:06 -0400
committerSage Weil <sage@newdream.net>2009-10-06 14:31:06 -0400
commit0dee3c28af2fbe22ca62739a7f57da5435d35793 (patch)
treedd5992a4abc86c5931ce36258b972dbf48ab355d /fs/ceph/ceph_fs.c
parent7ad920b504a980adcab4d3f6b85695526e6fd7bb (diff)
ceph: on-wire types
These headers describe the types used to exchange messages between the Ceph client and various servers. All types are little-endian and packed. These headers are shared between the kernel and userspace, so all types are in terms of e.g. __u32. Additionally, we define a few magic values to identify the current version of the protocol(s) in use, so that discrepancies to be detected on mount. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/ceph_fs.c')
-rw-r--r--fs/ceph/ceph_fs.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/fs/ceph/ceph_fs.c b/fs/ceph/ceph_fs.c
new file mode 100644
index 000000000000..9371ff1c0002
--- /dev/null
+++ b/fs/ceph/ceph_fs.c
@@ -0,0 +1,80 @@
1/*
2 * Some non-inline ceph helpers
3 */
4#include "types.h"
5
6int ceph_flags_to_mode(int flags)
7{
8#ifdef O_DIRECTORY /* fixme */
9 if ((flags & O_DIRECTORY) == O_DIRECTORY)
10 return CEPH_FILE_MODE_PIN;
11#endif
12#ifdef O_LAZY
13 if (flags & O_LAZY)
14 return CEPH_FILE_MODE_LAZY;
15#endif
16 if ((flags & O_APPEND) == O_APPEND)
17 flags |= O_WRONLY;
18
19 flags &= O_ACCMODE;
20 if ((flags & O_RDWR) == O_RDWR)
21 return CEPH_FILE_MODE_RDWR;
22 if ((flags & O_WRONLY) == O_WRONLY)
23 return CEPH_FILE_MODE_WR;
24 return CEPH_FILE_MODE_RD;
25}
26
27int ceph_caps_for_mode(int mode)
28{
29 switch (mode) {
30 case CEPH_FILE_MODE_PIN:
31 return CEPH_CAP_PIN;
32 case CEPH_FILE_MODE_RD:
33 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
34 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
35 case CEPH_FILE_MODE_RDWR:
36 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
37 CEPH_CAP_FILE_EXCL |
38 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE |
39 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
40 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
41 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
42 case CEPH_FILE_MODE_WR:
43 return CEPH_CAP_PIN | CEPH_CAP_FILE_SHARED |
44 CEPH_CAP_FILE_EXCL |
45 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
46 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
47 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
48 }
49 return 0;
50}
51
52/* Name hashing routines. Initial hash value */
53/* Hash courtesy of the R5 hash in reiserfs modulo sign bits */
54#define ceph_init_name_hash() 0
55
56/* partial hash update function. Assume roughly 4 bits per character */
57static unsigned long ceph_partial_name_hash(unsigned long c,
58 unsigned long prevhash)
59{
60 return (prevhash + (c << 4) + (c >> 4)) * 11;
61}
62
63/*
64 * Finally: cut down the number of bits to a int value (and try to avoid
65 * losing bits)
66 */
67static unsigned long ceph_end_name_hash(unsigned long hash)
68{
69 return hash & 0xffffffff;
70}
71
72/* Compute the hash for a name string. */
73unsigned int ceph_full_name_hash(const char *name, unsigned int len)
74{
75 unsigned long hash = ceph_init_name_hash();
76 while (len--)
77 hash = ceph_partial_name_hash(*name++, hash);
78 return ceph_end_name_hash(hash);
79}
80