blob: 3ac6cc7c1156dafd78262e7290edf914c3f01e31 [file] [log] [blame]
Sage Weil0dee3c22009-10-06 11:31:06 -07001/*
2 * Some non-inline ceph helpers
3 */
4#include "types.h"
5
Sage Weil752727a2009-10-09 16:38:45 -07006/*
7 * return true if @layout appears to be valid
8 */
9int ceph_file_layout_is_valid(const struct ceph_file_layout *layout)
10{
11 __u32 su = le32_to_cpu(layout->fl_stripe_unit);
12 __u32 sc = le32_to_cpu(layout->fl_stripe_count);
13 __u32 os = le32_to_cpu(layout->fl_object_size);
14
15 /* stripe unit, object size must be non-zero, 64k increment */
16 if (!su || (su & (CEPH_MIN_STRIPE_UNIT-1)))
17 return 0;
18 if (!os || (os & (CEPH_MIN_STRIPE_UNIT-1)))
19 return 0;
20 /* object size must be a multiple of stripe unit */
21 if (os < su || os % su)
22 return 0;
23 /* stripe count must be non-zero */
24 if (!sc)
25 return 0;
26 return 1;
27}
28
29
Sage Weil0dee3c22009-10-06 11:31:06 -070030int ceph_flags_to_mode(int flags)
31{
Sage Weil84d95092010-05-25 16:46:24 -070032 int mode;
33
Sage Weil0dee3c22009-10-06 11:31:06 -070034#ifdef O_DIRECTORY /* fixme */
35 if ((flags & O_DIRECTORY) == O_DIRECTORY)
36 return CEPH_FILE_MODE_PIN;
37#endif
Sage Weil0dee3c22009-10-06 11:31:06 -070038 if ((flags & O_APPEND) == O_APPEND)
39 flags |= O_WRONLY;
40
Sage Weil84d95092010-05-25 16:46:24 -070041 if ((flags & O_ACCMODE) == O_RDWR)
42 mode = CEPH_FILE_MODE_RDWR;
43 else if ((flags & O_ACCMODE) == O_WRONLY)
44 mode = CEPH_FILE_MODE_WR;
45 else
46 mode = CEPH_FILE_MODE_RD;
47
48#ifdef O_LAZY
49 if (flags & O_LAZY)
50 mode |= CEPH_FILE_MODE_LAZY;
51#endif
52
53 return mode;
Sage Weil0dee3c22009-10-06 11:31:06 -070054}
55
56int ceph_caps_for_mode(int mode)
57{
Sage Weil84d95092010-05-25 16:46:24 -070058 int caps = CEPH_CAP_PIN;
59
60 if (mode & CEPH_FILE_MODE_RD)
61 caps |= CEPH_CAP_FILE_SHARED |
Sage Weil0dee3c22009-10-06 11:31:06 -070062 CEPH_CAP_FILE_RD | CEPH_CAP_FILE_CACHE;
Sage Weil84d95092010-05-25 16:46:24 -070063 if (mode & CEPH_FILE_MODE_WR)
64 caps |= CEPH_CAP_FILE_EXCL |
Sage Weil0dee3c22009-10-06 11:31:06 -070065 CEPH_CAP_FILE_WR | CEPH_CAP_FILE_BUFFER |
66 CEPH_CAP_AUTH_SHARED | CEPH_CAP_AUTH_EXCL |
67 CEPH_CAP_XATTR_SHARED | CEPH_CAP_XATTR_EXCL;
Sage Weil84d95092010-05-25 16:46:24 -070068 if (mode & CEPH_FILE_MODE_LAZY)
69 caps |= CEPH_CAP_FILE_LAZYIO;
70
71 return caps;
Sage Weil0dee3c22009-10-06 11:31:06 -070072}