Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 2 | |
| 3 | #include <linux/spinlock.h> |
| 4 | #include <linux/fs_struct.h> |
| 5 | #include <linux/namei.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 7 | #include <linux/sched.h> |
Andreas Gruenbacher | 2cdeb1e | 2016-04-14 00:30:17 +0200 | [diff] [blame] | 8 | #include <linux/xattr.h> |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 9 | |
| 10 | #include "super.h" |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 11 | #include "mds_client.h" |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 12 | |
| 13 | /* |
| 14 | * Directory operations: readdir, lookup, create, link, unlink, |
| 15 | * rename, etc. |
| 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Ceph MDS operations are specified in terms of a base ino and |
| 20 | * relative path. Thus, the client can specify an operation on a |
| 21 | * specific inode (e.g., a getattr due to fstat(2)), or as a path |
| 22 | * relative to, say, the root directory. |
| 23 | * |
| 24 | * Normally, we limit ourselves to strict inode ops (no path component) |
| 25 | * or dentry operations (a single path component relative to an ino). The |
| 26 | * exception to this is open_root_dentry(), which will open the mount |
| 27 | * point by name. |
| 28 | */ |
| 29 | |
Sage Weil | 52dfb8a | 2010-08-03 10:25:30 -0700 | [diff] [blame] | 30 | const struct dentry_operations ceph_dentry_ops; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Initialize ceph dentry state. |
| 34 | */ |
| 35 | int ceph_init_dentry(struct dentry *dentry) |
| 36 | { |
| 37 | struct ceph_dentry_info *di; |
| 38 | |
| 39 | if (dentry->d_fsdata) |
| 40 | return 0; |
| 41 | |
Geliang Tang | 99ec269 | 2016-03-13 15:26:29 +0800 | [diff] [blame] | 42 | di = kmem_cache_zalloc(ceph_dentry_cachep, GFP_KERNEL); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 43 | if (!di) |
| 44 | return -ENOMEM; /* oh well */ |
| 45 | |
| 46 | spin_lock(&dentry->d_lock); |
Sage Weil | 8c6efb5 | 2010-04-23 11:36:54 -0700 | [diff] [blame] | 47 | if (dentry->d_fsdata) { |
| 48 | /* lost a race */ |
| 49 | kmem_cache_free(ceph_dentry_cachep, di); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 50 | goto out_unlock; |
Sage Weil | 8c6efb5 | 2010-04-23 11:36:54 -0700 | [diff] [blame] | 51 | } |
Sage Weil | 48d0cbd | 2011-07-26 11:30:15 -0700 | [diff] [blame] | 52 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 53 | if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_NOSNAP) |
Sage Weil | 48d0cbd | 2011-07-26 11:30:15 -0700 | [diff] [blame] | 54 | d_set_d_op(dentry, &ceph_dentry_ops); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 55 | else if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_SNAPDIR) |
Sage Weil | 48d0cbd | 2011-07-26 11:30:15 -0700 | [diff] [blame] | 56 | d_set_d_op(dentry, &ceph_snapdir_dentry_ops); |
| 57 | else |
| 58 | d_set_d_op(dentry, &ceph_snap_dentry_ops); |
| 59 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 60 | di->dentry = dentry; |
| 61 | di->lease_session = NULL; |
Miklos Szeredi | 9b16f03c | 2016-06-22 16:35:04 +0200 | [diff] [blame] | 62 | di->time = jiffies; |
Sage Weil | 48d0cbd | 2011-07-26 11:30:15 -0700 | [diff] [blame] | 63 | /* avoid reordering d_fsdata setup so that the check above is safe */ |
| 64 | smp_mb(); |
| 65 | dentry->d_fsdata = di; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 66 | ceph_dentry_lru_add(dentry); |
| 67 | out_unlock: |
| 68 | spin_unlock(&dentry->d_lock); |
| 69 | return 0; |
| 70 | } |
| 71 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 72 | /* |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 73 | * for f_pos for readdir: |
| 74 | * - hash order: |
| 75 | * (0xff << 52) | ((24 bits hash) << 28) | |
| 76 | * (the nth entry has hash collision); |
| 77 | * - frag+name order; |
| 78 | * ((frag value) << 28) | (the nth entry in frag); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 79 | */ |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 80 | #define OFFSET_BITS 28 |
| 81 | #define OFFSET_MASK ((1 << OFFSET_BITS) - 1) |
| 82 | #define HASH_ORDER (0xffull << (OFFSET_BITS + 24)) |
| 83 | loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order) |
| 84 | { |
| 85 | loff_t fpos = ((loff_t)high << 28) | (loff_t)off; |
| 86 | if (hash_order) |
| 87 | fpos |= HASH_ORDER; |
| 88 | return fpos; |
| 89 | } |
| 90 | |
| 91 | static bool is_hash_order(loff_t p) |
| 92 | { |
| 93 | return (p & HASH_ORDER) == HASH_ORDER; |
| 94 | } |
| 95 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 96 | static unsigned fpos_frag(loff_t p) |
| 97 | { |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 98 | return p >> OFFSET_BITS; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 99 | } |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 100 | |
| 101 | static unsigned fpos_hash(loff_t p) |
| 102 | { |
| 103 | return ceph_frag_value(fpos_frag(p)); |
| 104 | } |
| 105 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 106 | static unsigned fpos_off(loff_t p) |
| 107 | { |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 108 | return p & OFFSET_MASK; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Yan, Zheng | 4d5f5df | 2014-02-13 19:40:26 +0800 | [diff] [blame] | 111 | static int fpos_cmp(loff_t l, loff_t r) |
| 112 | { |
| 113 | int v = ceph_frag_compare(fpos_frag(l), fpos_frag(r)); |
| 114 | if (v) |
| 115 | return v; |
| 116 | return (int)(fpos_off(l) - fpos_off(r)); |
| 117 | } |
| 118 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 119 | /* |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 120 | * make note of the last dentry we read, so we can |
| 121 | * continue at the same lexicographical point, |
| 122 | * regardless of what dir changes take place on the |
| 123 | * server. |
| 124 | */ |
| 125 | static int note_last_dentry(struct ceph_file_info *fi, const char *name, |
| 126 | int len, unsigned next_offset) |
| 127 | { |
| 128 | char *buf = kmalloc(len+1, GFP_KERNEL); |
| 129 | if (!buf) |
| 130 | return -ENOMEM; |
| 131 | kfree(fi->last_name); |
| 132 | fi->last_name = buf; |
| 133 | memcpy(fi->last_name, name, len); |
| 134 | fi->last_name[len] = 0; |
| 135 | fi->next_offset = next_offset; |
| 136 | dout("note_last_dentry '%s'\n", fi->last_name); |
| 137 | return 0; |
| 138 | } |
| 139 | |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 140 | |
| 141 | static struct dentry * |
| 142 | __dcache_find_get_entry(struct dentry *parent, u64 idx, |
| 143 | struct ceph_readdir_cache_control *cache_ctl) |
| 144 | { |
| 145 | struct inode *dir = d_inode(parent); |
| 146 | struct dentry *dentry; |
| 147 | unsigned idx_mask = (PAGE_SIZE / sizeof(struct dentry *)) - 1; |
| 148 | loff_t ptr_pos = idx * sizeof(struct dentry *); |
| 149 | pgoff_t ptr_pgoff = ptr_pos >> PAGE_SHIFT; |
| 150 | |
| 151 | if (ptr_pos >= i_size_read(dir)) |
| 152 | return NULL; |
| 153 | |
| 154 | if (!cache_ctl->page || ptr_pgoff != page_index(cache_ctl->page)) { |
| 155 | ceph_readdir_cache_release(cache_ctl); |
| 156 | cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff); |
| 157 | if (!cache_ctl->page) { |
| 158 | dout(" page %lu not found\n", ptr_pgoff); |
| 159 | return ERR_PTR(-EAGAIN); |
| 160 | } |
| 161 | /* reading/filling the cache are serialized by |
| 162 | i_mutex, no need to use page lock */ |
| 163 | unlock_page(cache_ctl->page); |
| 164 | cache_ctl->dentries = kmap(cache_ctl->page); |
| 165 | } |
| 166 | |
| 167 | cache_ctl->index = idx & idx_mask; |
| 168 | |
| 169 | rcu_read_lock(); |
| 170 | spin_lock(&parent->d_lock); |
| 171 | /* check i_size again here, because empty directory can be |
| 172 | * marked as complete while not holding the i_mutex. */ |
| 173 | if (ceph_dir_is_complete_ordered(dir) && ptr_pos < i_size_read(dir)) |
| 174 | dentry = cache_ctl->dentries[cache_ctl->index]; |
| 175 | else |
| 176 | dentry = NULL; |
| 177 | spin_unlock(&parent->d_lock); |
| 178 | if (dentry && !lockref_get_not_dead(&dentry->d_lockref)) |
| 179 | dentry = NULL; |
| 180 | rcu_read_unlock(); |
| 181 | return dentry ? : ERR_PTR(-EAGAIN); |
| 182 | } |
| 183 | |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 184 | /* |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 185 | * When possible, we try to satisfy a readdir by peeking at the |
| 186 | * dcache. We make this work by carefully ordering dentries on |
Al Viro | 946e51f | 2014-10-26 19:19:16 -0400 | [diff] [blame] | 187 | * d_child when we initially get results back from the MDS, and |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 188 | * falling back to a "normal" sync readdir if any dentries in the dir |
| 189 | * are dropped. |
| 190 | * |
Yan, Zheng | 2f276c5 | 2013-03-13 19:44:32 +0800 | [diff] [blame] | 191 | * Complete dir indicates that we have all dentries in the dir. It is |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 192 | * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by |
| 193 | * the MDS if/when the directory is modified). |
| 194 | */ |
Yan, Zheng | a30be7c | 2014-04-06 14:10:04 +0800 | [diff] [blame] | 195 | static int __dcache_readdir(struct file *file, struct dir_context *ctx, |
| 196 | u32 shared_gen) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 197 | { |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 198 | struct ceph_file_info *fi = file->private_data; |
Al Viro | b583043 | 2014-10-31 01:22:04 -0400 | [diff] [blame] | 199 | struct dentry *parent = file->f_path.dentry; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 200 | struct inode *dir = d_inode(parent); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 201 | struct dentry *dentry, *last = NULL; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 202 | struct ceph_dentry_info *di; |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 203 | struct ceph_readdir_cache_control cache_ctl = {}; |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 204 | u64 idx = 0; |
| 205 | int err = 0; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 206 | |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 207 | dout("__dcache_readdir %p v%u at %llx\n", dir, shared_gen, ctx->pos); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 208 | |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 209 | /* search start position */ |
| 210 | if (ctx->pos > 2) { |
| 211 | u64 count = div_u64(i_size_read(dir), sizeof(struct dentry *)); |
| 212 | while (count > 0) { |
| 213 | u64 step = count >> 1; |
| 214 | dentry = __dcache_find_get_entry(parent, idx + step, |
| 215 | &cache_ctl); |
| 216 | if (!dentry) { |
| 217 | /* use linar search */ |
| 218 | idx = 0; |
| 219 | break; |
| 220 | } |
| 221 | if (IS_ERR(dentry)) { |
| 222 | err = PTR_ERR(dentry); |
| 223 | goto out; |
| 224 | } |
| 225 | di = ceph_dentry(dentry); |
| 226 | spin_lock(&dentry->d_lock); |
| 227 | if (fpos_cmp(di->offset, ctx->pos) < 0) { |
| 228 | idx += step + 1; |
| 229 | count -= step + 1; |
| 230 | } else { |
| 231 | count = step; |
| 232 | } |
| 233 | spin_unlock(&dentry->d_lock); |
| 234 | dput(dentry); |
| 235 | } |
| 236 | |
| 237 | dout("__dcache_readdir %p cache idx %llu\n", dir, idx); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 240 | |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 241 | for (;;) { |
| 242 | bool emit_dentry = false; |
| 243 | dentry = __dcache_find_get_entry(parent, idx++, &cache_ctl); |
| 244 | if (!dentry) { |
Sage Weil | 9cfa109 | 2011-07-26 11:26:18 -0700 | [diff] [blame] | 245 | fi->flags |= CEPH_F_ATEND; |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 246 | err = 0; |
| 247 | break; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 248 | } |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 249 | if (IS_ERR(dentry)) { |
| 250 | err = PTR_ERR(dentry); |
| 251 | goto out; |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 252 | } |
| 253 | |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 254 | di = ceph_dentry(dentry); |
| 255 | spin_lock(&dentry->d_lock); |
Yan, Zheng | a30be7c | 2014-04-06 14:10:04 +0800 | [diff] [blame] | 256 | if (di->lease_shared_gen == shared_gen && |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 257 | d_really_is_positive(dentry) && |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 258 | fpos_cmp(ctx->pos, di->offset) <= 0) { |
| 259 | emit_dentry = true; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 260 | } |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 261 | spin_unlock(&dentry->d_lock); |
| 262 | |
| 263 | if (emit_dentry) { |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 264 | dout(" %llx dentry %p %pd %p\n", di->offset, |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 265 | dentry, dentry, d_inode(dentry)); |
| 266 | ctx->pos = di->offset; |
| 267 | if (!dir_emit(ctx, dentry->d_name.name, |
| 268 | dentry->d_name.len, |
| 269 | ceph_translate_ino(dentry->d_sb, |
| 270 | d_inode(dentry)->i_ino), |
| 271 | d_inode(dentry)->i_mode >> 12)) { |
| 272 | dput(dentry); |
| 273 | err = 0; |
| 274 | break; |
| 275 | } |
| 276 | ctx->pos++; |
| 277 | |
| 278 | if (last) |
| 279 | dput(last); |
| 280 | last = dentry; |
| 281 | } else { |
| 282 | dput(dentry); |
| 283 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 284 | } |
Yan, Zheng | c530cd2 | 2016-04-28 17:43:35 +0800 | [diff] [blame] | 285 | out: |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 286 | ceph_readdir_cache_release(&cache_ctl); |
| 287 | if (last) { |
| 288 | int ret; |
| 289 | di = ceph_dentry(last); |
| 290 | ret = note_last_dentry(fi, last->d_name.name, last->d_name.len, |
| 291 | fpos_off(di->offset) + 1); |
| 292 | if (ret < 0) |
| 293 | err = ret; |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 294 | dput(last); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 295 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 296 | return err; |
| 297 | } |
| 298 | |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 299 | static bool need_send_readdir(struct ceph_file_info *fi, loff_t pos) |
| 300 | { |
| 301 | if (!fi->last_readdir) |
| 302 | return true; |
| 303 | if (is_hash_order(pos)) |
| 304 | return !ceph_frag_contains_value(fi->frag, fpos_hash(pos)); |
| 305 | else |
| 306 | return fi->frag != fpos_frag(pos); |
| 307 | } |
| 308 | |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 309 | static int ceph_readdir(struct file *file, struct dir_context *ctx) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 310 | { |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 311 | struct ceph_file_info *fi = file->private_data; |
| 312 | struct inode *inode = file_inode(file); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 313 | struct ceph_inode_info *ci = ceph_inode(inode); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 314 | struct ceph_fs_client *fsc = ceph_inode_to_client(inode); |
| 315 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 316 | int i; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 317 | int err; |
| 318 | u32 ftype; |
| 319 | struct ceph_mds_reply_info_parsed *rinfo; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 320 | |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 321 | dout("readdir %p file %p pos %llx\n", inode, file, ctx->pos); |
Sage Weil | 9cfa109 | 2011-07-26 11:26:18 -0700 | [diff] [blame] | 322 | if (fi->flags & CEPH_F_ATEND) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 323 | return 0; |
| 324 | |
| 325 | /* always start with . and .. */ |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 326 | if (ctx->pos == 0) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 327 | dout("readdir off 0 -> '.'\n"); |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 328 | if (!dir_emit(ctx, ".", 1, |
Yehuda Sadeh | ad1fee9 | 2011-01-21 16:44:03 -0800 | [diff] [blame] | 329 | ceph_translate_ino(inode->i_sb, inode->i_ino), |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 330 | inode->i_mode >> 12)) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 331 | return 0; |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 332 | ctx->pos = 1; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 333 | } |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 334 | if (ctx->pos == 1) { |
Al Viro | b583043 | 2014-10-31 01:22:04 -0400 | [diff] [blame] | 335 | ino_t ino = parent_ino(file->f_path.dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 336 | dout("readdir off 1 -> '..'\n"); |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 337 | if (!dir_emit(ctx, "..", 2, |
Yehuda Sadeh | ad1fee9 | 2011-01-21 16:44:03 -0800 | [diff] [blame] | 338 | ceph_translate_ino(inode->i_sb, ino), |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 339 | inode->i_mode >> 12)) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 340 | return 0; |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 341 | ctx->pos = 2; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* can we use the dcache? */ |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 345 | spin_lock(&ci->i_ceph_lock); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 346 | if (ceph_test_mount_opt(fsc, DCACHE) && |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 347 | !ceph_test_mount_opt(fsc, NOASYNCREADDIR) && |
Sage Weil | a0dff78 | 2010-07-22 13:47:21 -0700 | [diff] [blame] | 348 | ceph_snap(inode) != CEPH_SNAPDIR && |
Yan, Zheng | 70db4f3 | 2014-10-21 18:09:56 -0700 | [diff] [blame] | 349 | __ceph_dir_is_complete_ordered(ci) && |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 350 | __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) { |
Yan, Zheng | a30be7c | 2014-04-06 14:10:04 +0800 | [diff] [blame] | 351 | u32 shared_gen = ci->i_shared_gen; |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 352 | spin_unlock(&ci->i_ceph_lock); |
Yan, Zheng | a30be7c | 2014-04-06 14:10:04 +0800 | [diff] [blame] | 353 | err = __dcache_readdir(file, ctx, shared_gen); |
Sage Weil | efa4c12 | 2010-10-18 14:04:31 -0700 | [diff] [blame] | 354 | if (err != -EAGAIN) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 355 | return err; |
Sage Weil | efa4c12 | 2010-10-18 14:04:31 -0700 | [diff] [blame] | 356 | } else { |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 357 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 358 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 359 | |
| 360 | /* proceed with a normal readdir */ |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 361 | more: |
| 362 | /* do we have the correct frag content buffered? */ |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 363 | if (need_send_readdir(fi, ctx->pos)) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 364 | struct ceph_mds_request *req; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 365 | unsigned frag; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 366 | int op = ceph_snap(inode) == CEPH_SNAPDIR ? |
| 367 | CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR; |
| 368 | |
| 369 | /* discard old result, if any */ |
Sage Weil | 393f662 | 2010-03-10 12:03:32 -0800 | [diff] [blame] | 370 | if (fi->last_readdir) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 371 | ceph_mdsc_put_request(fi->last_readdir); |
Sage Weil | 393f662 | 2010-03-10 12:03:32 -0800 | [diff] [blame] | 372 | fi->last_readdir = NULL; |
| 373 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 374 | |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 375 | if (is_hash_order(ctx->pos)) { |
| 376 | frag = ceph_choose_frag(ci, fpos_hash(ctx->pos), |
| 377 | NULL, NULL); |
| 378 | } else { |
| 379 | frag = fpos_frag(ctx->pos); |
| 380 | } |
| 381 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 382 | dout("readdir fetching %llx.%llx frag %x offset '%s'\n", |
| 383 | ceph_vinop(inode), frag, fi->last_name); |
| 384 | req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); |
| 385 | if (IS_ERR(req)) |
| 386 | return PTR_ERR(req); |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 387 | err = ceph_alloc_readdir_reply_buffer(req, inode); |
| 388 | if (err) { |
| 389 | ceph_mdsc_put_request(req); |
| 390 | return err; |
| 391 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 392 | /* hints to request -> mds selection code */ |
| 393 | req->r_direct_mode = USE_AUTH_MDS; |
| 394 | req->r_direct_hash = ceph_frag_value(frag); |
| 395 | req->r_direct_is_hash = true; |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 396 | if (fi->last_name) { |
Yan, Zheng | 687265e | 2015-06-13 17:27:05 +0800 | [diff] [blame] | 397 | req->r_path2 = kstrdup(fi->last_name, GFP_KERNEL); |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 398 | if (!req->r_path2) { |
| 399 | ceph_mdsc_put_request(req); |
| 400 | return -ENOMEM; |
| 401 | } |
| 402 | } |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 403 | req->r_dir_release_cnt = fi->dir_release_count; |
| 404 | req->r_dir_ordered_cnt = fi->dir_ordered_count; |
| 405 | req->r_readdir_cache_idx = fi->readdir_cache_idx; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 406 | req->r_readdir_offset = fi->next_offset; |
| 407 | req->r_args.readdir.frag = cpu_to_le32(frag); |
Yan, Zheng | 956d39d | 2016-04-27 17:48:30 +0800 | [diff] [blame] | 408 | req->r_args.readdir.flags = |
| 409 | cpu_to_le16(CEPH_READDIR_REPLY_BITFLAGS); |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 410 | |
| 411 | req->r_inode = inode; |
| 412 | ihold(inode); |
| 413 | req->r_dentry = dget(file->f_path.dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 414 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
| 415 | if (err < 0) { |
| 416 | ceph_mdsc_put_request(req); |
| 417 | return err; |
| 418 | } |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 419 | dout("readdir got and parsed readdir result=%d on " |
| 420 | "frag %x, end=%d, complete=%d, hash_order=%d\n", |
| 421 | err, frag, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 422 | (int)req->r_reply_info.dir_end, |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 423 | (int)req->r_reply_info.dir_complete, |
| 424 | (int)req->r_reply_info.hash_order); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 425 | |
Yan, Zheng | 81c6aea | 2013-09-18 09:44:13 +0800 | [diff] [blame] | 426 | rinfo = &req->r_reply_info; |
| 427 | if (le32_to_cpu(rinfo->dir_dir->frag) != frag) { |
| 428 | frag = le32_to_cpu(rinfo->dir_dir->frag); |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 429 | if (!rinfo->hash_order) { |
| 430 | fi->next_offset = req->r_readdir_offset; |
| 431 | /* adjust ctx->pos to beginning of frag */ |
| 432 | ctx->pos = ceph_make_fpos(frag, |
| 433 | fi->next_offset, |
| 434 | false); |
| 435 | } |
Yan, Zheng | 81c6aea | 2013-09-18 09:44:13 +0800 | [diff] [blame] | 436 | } |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 437 | |
Yan, Zheng | f049420 | 2014-02-27 16:26:24 +0800 | [diff] [blame] | 438 | fi->frag = frag; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 439 | fi->last_readdir = req; |
| 440 | |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 441 | if (req->r_did_prepopulate) { |
| 442 | fi->readdir_cache_idx = req->r_readdir_cache_idx; |
| 443 | if (fi->readdir_cache_idx < 0) { |
| 444 | /* preclude from marking dir ordered */ |
| 445 | fi->dir_ordered_count = 0; |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 446 | } else if (ceph_frag_is_leftmost(frag) && |
| 447 | fi->next_offset == 2) { |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 448 | /* note dir version at start of readdir so |
| 449 | * we can tell if any dentries get dropped */ |
| 450 | fi->dir_release_count = req->r_dir_release_cnt; |
| 451 | fi->dir_ordered_count = req->r_dir_ordered_cnt; |
| 452 | } |
| 453 | } else { |
| 454 | dout("readdir !did_prepopulate"); |
| 455 | /* disable readdir cache */ |
| 456 | fi->readdir_cache_idx = -1; |
| 457 | /* preclude from marking dir complete */ |
| 458 | fi->dir_release_count = 0; |
| 459 | } |
| 460 | |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 461 | /* note next offset and last dentry name */ |
| 462 | if (rinfo->dir_nr > 0) { |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 463 | struct ceph_mds_reply_dir_entry *rde = |
| 464 | rinfo->dir_entries + (rinfo->dir_nr-1); |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 465 | unsigned next_offset = req->r_reply_info.dir_end ? |
| 466 | 2 : (fpos_off(rde->offset) + 1); |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 467 | err = note_last_dentry(fi, rde->name, rde->name_len, |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 468 | next_offset); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 469 | if (err) |
| 470 | return err; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 471 | } else if (req->r_reply_info.dir_end) { |
| 472 | fi->next_offset = 2; |
| 473 | /* keep last name */ |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | rinfo = &fi->last_readdir->r_reply_info; |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 478 | dout("readdir frag %x num %d pos %llx chunk first %llx\n", |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 479 | fi->frag, rinfo->dir_nr, ctx->pos, |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 480 | rinfo->dir_nr ? rinfo->dir_entries[0].offset : 0LL); |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 481 | |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 482 | i = 0; |
| 483 | /* search start position */ |
| 484 | if (rinfo->dir_nr > 0) { |
| 485 | int step, nr = rinfo->dir_nr; |
| 486 | while (nr > 0) { |
| 487 | step = nr >> 1; |
| 488 | if (rinfo->dir_entries[i + step].offset < ctx->pos) { |
| 489 | i += step + 1; |
| 490 | nr -= step + 1; |
| 491 | } else { |
| 492 | nr = step; |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | for (; i < rinfo->dir_nr; i++) { |
| 497 | struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i; |
Sage Weil | 3105c19 | 2010-11-18 09:15:07 -0800 | [diff] [blame] | 498 | struct ceph_vino vino; |
| 499 | ino_t ino; |
| 500 | |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 501 | BUG_ON(rde->offset < ctx->pos); |
| 502 | |
| 503 | ctx->pos = rde->offset; |
| 504 | dout("readdir (%d/%d) -> %llx '%.*s' %p\n", |
| 505 | i, rinfo->dir_nr, ctx->pos, |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 506 | rde->name_len, rde->name, &rde->inode.in); |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 507 | |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 508 | BUG_ON(!rde->inode.in); |
| 509 | ftype = le32_to_cpu(rde->inode.in->mode) >> 12; |
| 510 | vino.ino = le64_to_cpu(rde->inode.in->ino); |
| 511 | vino.snap = le64_to_cpu(rde->inode.in->snapid); |
Sage Weil | 3105c19 | 2010-11-18 09:15:07 -0800 | [diff] [blame] | 512 | ino = ceph_vino_to_ino(vino); |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 513 | |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 514 | if (!dir_emit(ctx, rde->name, rde->name_len, |
| 515 | ceph_translate_ino(inode->i_sb, ino), ftype)) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 516 | dout("filldir stopping us...\n"); |
| 517 | return 0; |
| 518 | } |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 519 | ctx->pos++; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 522 | if (fi->next_offset > 2) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 523 | ceph_mdsc_put_request(fi->last_readdir); |
| 524 | fi->last_readdir = NULL; |
| 525 | goto more; |
| 526 | } |
| 527 | |
| 528 | /* more frags? */ |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 529 | if (!ceph_frag_is_rightmost(fi->frag)) { |
| 530 | unsigned frag = ceph_frag_next(fi->frag); |
| 531 | if (is_hash_order(ctx->pos)) { |
| 532 | loff_t new_pos = ceph_make_fpos(ceph_frag_value(frag), |
| 533 | fi->next_offset, true); |
| 534 | if (new_pos > ctx->pos) |
| 535 | ctx->pos = new_pos; |
| 536 | /* keep last_name */ |
| 537 | } else { |
| 538 | ctx->pos = ceph_make_fpos(frag, fi->next_offset, false); |
| 539 | kfree(fi->last_name); |
| 540 | fi->last_name = NULL; |
| 541 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 542 | dout("readdir next frag is %x\n", frag); |
| 543 | goto more; |
| 544 | } |
Sage Weil | 9cfa109 | 2011-07-26 11:26:18 -0700 | [diff] [blame] | 545 | fi->flags |= CEPH_F_ATEND; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * if dir_release_count still matches the dir, no dentries |
| 549 | * were released during the whole readdir, and we should have |
| 550 | * the complete dir contents in our cache. |
| 551 | */ |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 552 | if (atomic64_read(&ci->i_release_count) == fi->dir_release_count) { |
| 553 | spin_lock(&ci->i_ceph_lock); |
| 554 | if (fi->dir_ordered_count == atomic64_read(&ci->i_ordered_count)) { |
Yan, Zheng | 70db4f3 | 2014-10-21 18:09:56 -0700 | [diff] [blame] | 555 | dout(" marking %p complete and ordered\n", inode); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 556 | /* use i_size to track number of entries in |
| 557 | * readdir cache */ |
| 558 | BUG_ON(fi->readdir_cache_idx < 0); |
| 559 | i_size_write(inode, fi->readdir_cache_idx * |
| 560 | sizeof(struct dentry*)); |
| 561 | } else { |
Yan, Zheng | 70db4f3 | 2014-10-21 18:09:56 -0700 | [diff] [blame] | 562 | dout(" marking %p complete\n", inode); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 563 | } |
Yan, Zheng | 70db4f3 | 2014-10-21 18:09:56 -0700 | [diff] [blame] | 564 | __ceph_dir_set_complete(ci, fi->dir_release_count, |
| 565 | fi->dir_ordered_count); |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 566 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 567 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 568 | |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 569 | dout("readdir %p file %p done.\n", inode, file); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 573 | static void reset_readdir(struct ceph_file_info *fi) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 574 | { |
| 575 | if (fi->last_readdir) { |
| 576 | ceph_mdsc_put_request(fi->last_readdir); |
| 577 | fi->last_readdir = NULL; |
| 578 | } |
| 579 | kfree(fi->last_name); |
Sage Weil | a1629c3 | 2010-11-11 15:24:06 -0800 | [diff] [blame] | 580 | fi->last_name = NULL; |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 581 | fi->dir_release_count = 0; |
| 582 | fi->readdir_cache_idx = -1; |
Yan, Zheng | a78600e | 2016-04-27 17:32:34 +0800 | [diff] [blame] | 583 | fi->next_offset = 2; /* compensate for . and .. */ |
Sage Weil | 9cfa109 | 2011-07-26 11:26:18 -0700 | [diff] [blame] | 584 | fi->flags &= ~CEPH_F_ATEND; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 587 | /* |
| 588 | * discard buffered readdir content on seekdir(0), or seek to new frag, |
| 589 | * or seek prior to current chunk |
| 590 | */ |
| 591 | static bool need_reset_readdir(struct ceph_file_info *fi, loff_t new_pos) |
| 592 | { |
| 593 | struct ceph_mds_reply_info_parsed *rinfo; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 594 | loff_t chunk_offset; |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 595 | if (new_pos == 0) |
| 596 | return true; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 597 | if (is_hash_order(new_pos)) { |
| 598 | /* no need to reset last_name for a forward seek when |
| 599 | * dentries are sotred in hash order */ |
| 600 | } else if (fi->frag |= fpos_frag(new_pos)) { |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 601 | return true; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 602 | } |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 603 | rinfo = fi->last_readdir ? &fi->last_readdir->r_reply_info : NULL; |
| 604 | if (!rinfo || !rinfo->dir_nr) |
| 605 | return true; |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 606 | chunk_offset = rinfo->dir_entries[0].offset; |
| 607 | return new_pos < chunk_offset || |
| 608 | is_hash_order(new_pos) != is_hash_order(chunk_offset); |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 609 | } |
| 610 | |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 611 | static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 612 | { |
| 613 | struct ceph_file_info *fi = file->private_data; |
| 614 | struct inode *inode = file->f_mapping->host; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 615 | loff_t retval; |
| 616 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 617 | inode_lock(inode); |
Josef Bacik | 06222e4 | 2011-07-18 13:21:38 -0400 | [diff] [blame] | 618 | retval = -EINVAL; |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 619 | switch (whence) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 620 | case SEEK_CUR: |
| 621 | offset += file->f_pos; |
Josef Bacik | 06222e4 | 2011-07-18 13:21:38 -0400 | [diff] [blame] | 622 | case SEEK_SET: |
| 623 | break; |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 624 | case SEEK_END: |
| 625 | retval = -EOPNOTSUPP; |
Josef Bacik | 06222e4 | 2011-07-18 13:21:38 -0400 | [diff] [blame] | 626 | default: |
| 627 | goto out; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 628 | } |
Josef Bacik | 06222e4 | 2011-07-18 13:21:38 -0400 | [diff] [blame] | 629 | |
Yan, Zheng | f049420 | 2014-02-27 16:26:24 +0800 | [diff] [blame] | 630 | if (offset >= 0) { |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 631 | if (need_reset_readdir(fi, offset)) { |
| 632 | dout("dir_llseek dropping %p content\n", file); |
| 633 | reset_readdir(fi); |
| 634 | } else if (is_hash_order(offset) && offset > file->f_pos) { |
| 635 | /* for hash offset, we don't know if a forward seek |
| 636 | * is within same frag */ |
| 637 | fi->dir_release_count = 0; |
| 638 | fi->readdir_cache_idx = -1; |
| 639 | } |
| 640 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 641 | if (offset != file->f_pos) { |
| 642 | file->f_pos = offset; |
| 643 | file->f_version = 0; |
Sage Weil | 9cfa109 | 2011-07-26 11:26:18 -0700 | [diff] [blame] | 644 | fi->flags &= ~CEPH_F_ATEND; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 645 | } |
| 646 | retval = offset; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 647 | } |
Josef Bacik | 06222e4 | 2011-07-18 13:21:38 -0400 | [diff] [blame] | 648 | out: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 649 | inode_unlock(inode); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 650 | return retval; |
| 651 | } |
| 652 | |
| 653 | /* |
Sage Weil | 468640e | 2011-07-26 11:28:11 -0700 | [diff] [blame] | 654 | * Handle lookups for the hidden .snap directory. |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 655 | */ |
Sage Weil | 468640e | 2011-07-26 11:28:11 -0700 | [diff] [blame] | 656 | int ceph_handle_snapdir(struct ceph_mds_request *req, |
| 657 | struct dentry *dentry, int err) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 658 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 659 | struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 660 | struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */ |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 661 | |
| 662 | /* .snap dir? */ |
| 663 | if (err == -ENOENT && |
Sage Weil | 455cec0 | 2011-03-03 13:44:35 -0800 | [diff] [blame] | 664 | ceph_snap(parent) == CEPH_NOSNAP && |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 665 | strcmp(dentry->d_name.name, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 666 | fsc->mount_options->snapdir_name) == 0) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 667 | struct inode *inode = ceph_get_snapdir(parent); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 668 | dout("ENOENT on snapdir %p '%pd', linking to snapdir %p\n", |
| 669 | dentry, dentry, inode); |
Sage Weil | 9358c6d | 2010-03-30 13:54:41 -0700 | [diff] [blame] | 670 | BUG_ON(!d_unhashed(dentry)); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 671 | d_add(dentry, inode); |
| 672 | err = 0; |
| 673 | } |
Sage Weil | 468640e | 2011-07-26 11:28:11 -0700 | [diff] [blame] | 674 | return err; |
| 675 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 676 | |
Sage Weil | 468640e | 2011-07-26 11:28:11 -0700 | [diff] [blame] | 677 | /* |
| 678 | * Figure out final result of a lookup/open request. |
| 679 | * |
| 680 | * Mainly, make sure we return the final req->r_dentry (if it already |
| 681 | * existed) in place of the original VFS-provided dentry when they |
| 682 | * differ. |
| 683 | * |
| 684 | * Gracefully handle the case where the MDS replies with -ENOENT and |
| 685 | * no trace (which it may do, at its discretion, e.g., if it doesn't |
| 686 | * care to issue a lease on the negative dentry). |
| 687 | */ |
| 688 | struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, |
| 689 | struct dentry *dentry, int err) |
| 690 | { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 691 | if (err == -ENOENT) { |
| 692 | /* no trace? */ |
| 693 | err = 0; |
| 694 | if (!req->r_reply_info.head->is_dentry) { |
| 695 | dout("ENOENT and no trace, dentry %p inode %p\n", |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 696 | dentry, d_inode(dentry)); |
| 697 | if (d_really_is_positive(dentry)) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 698 | d_drop(dentry); |
| 699 | err = -ENOENT; |
| 700 | } else { |
| 701 | d_add(dentry, NULL); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | if (err) |
| 706 | dentry = ERR_PTR(err); |
| 707 | else if (dentry != req->r_dentry) |
| 708 | dentry = dget(req->r_dentry); /* we got spliced */ |
| 709 | else |
| 710 | dentry = NULL; |
| 711 | return dentry; |
| 712 | } |
| 713 | |
Zhang Zhuoyu | 3b33f69 | 2016-03-25 05:18:39 -0400 | [diff] [blame] | 714 | static bool is_root_ceph_dentry(struct inode *inode, struct dentry *dentry) |
Sage Weil | 1d1de916 | 2009-12-02 11:54:25 -0800 | [diff] [blame] | 715 | { |
| 716 | return ceph_ino(inode) == CEPH_INO_ROOT && |
| 717 | strncmp(dentry->d_name.name, ".ceph", 5) == 0; |
| 718 | } |
| 719 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 720 | /* |
| 721 | * Look up a single dir entry. If there is a lookup intent, inform |
| 722 | * the MDS so that it gets our 'caps wanted' value in a single op. |
| 723 | */ |
| 724 | static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 725 | unsigned int flags) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 726 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 727 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 728 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 729 | struct ceph_mds_request *req; |
| 730 | int op; |
Yan, Zheng | 315f240 | 2016-03-07 10:34:50 +0800 | [diff] [blame] | 731 | int mask; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 732 | int err; |
| 733 | |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 734 | dout("lookup %p dentry %p '%pd'\n", |
| 735 | dir, dentry, dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 736 | |
| 737 | if (dentry->d_name.len > NAME_MAX) |
| 738 | return ERR_PTR(-ENAMETOOLONG); |
| 739 | |
| 740 | err = ceph_init_dentry(dentry); |
| 741 | if (err < 0) |
| 742 | return ERR_PTR(err); |
| 743 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 744 | /* can we conclude ENOENT locally? */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 745 | if (d_really_is_negative(dentry)) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 746 | struct ceph_inode_info *ci = ceph_inode(dir); |
| 747 | struct ceph_dentry_info *di = ceph_dentry(dentry); |
| 748 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 749 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 750 | dout(" dir %p flags are %d\n", dir, ci->i_ceph_flags); |
| 751 | if (strncmp(dentry->d_name.name, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 752 | fsc->mount_options->snapdir_name, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 753 | dentry->d_name.len) && |
Sage Weil | 1d1de916 | 2009-12-02 11:54:25 -0800 | [diff] [blame] | 754 | !is_root_ceph_dentry(dir, dentry) && |
Yan, Zheng | e2c3de0 | 2015-03-04 16:05:04 +0800 | [diff] [blame] | 755 | ceph_test_mount_opt(fsc, DCACHE) && |
Yan, Zheng | 2f276c5 | 2013-03-13 19:44:32 +0800 | [diff] [blame] | 756 | __ceph_dir_is_complete(ci) && |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 757 | (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) { |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 758 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 759 | dout(" dir %p complete, -ENOENT\n", dir); |
| 760 | d_add(dentry, NULL); |
| 761 | di->lease_shared_gen = ci->i_shared_gen; |
| 762 | return NULL; |
| 763 | } |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 764 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | op = ceph_snap(dir) == CEPH_SNAPDIR ? |
| 768 | CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP; |
| 769 | req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS); |
| 770 | if (IS_ERR(req)) |
Julia Lawall | 7e34bc5 | 2010-05-22 12:01:14 +0200 | [diff] [blame] | 771 | return ERR_CAST(req); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 772 | req->r_dentry = dget(dentry); |
| 773 | req->r_num_caps = 2; |
Yan, Zheng | 315f240 | 2016-03-07 10:34:50 +0800 | [diff] [blame] | 774 | |
| 775 | mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED; |
| 776 | if (ceph_security_xattr_wanted(dir)) |
| 777 | mask |= CEPH_CAP_XATTR_SHARED; |
| 778 | req->r_args.getattr.mask = cpu_to_le32(mask); |
| 779 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 780 | req->r_locked_dir = dir; |
| 781 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
Sage Weil | 468640e | 2011-07-26 11:28:11 -0700 | [diff] [blame] | 782 | err = ceph_handle_snapdir(req, dentry, err); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 783 | dentry = ceph_finish_lookup(req, dentry, err); |
| 784 | ceph_mdsc_put_request(req); /* will dput(dentry) */ |
| 785 | dout("lookup result=%p\n", dentry); |
| 786 | return dentry; |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | * If we do a create but get no trace back from the MDS, follow up with |
| 791 | * a lookup (the VFS expects us to link up the provided dentry). |
| 792 | */ |
| 793 | int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry) |
| 794 | { |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 795 | struct dentry *result = ceph_lookup(dir, dentry, 0); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 796 | |
| 797 | if (result && !IS_ERR(result)) { |
| 798 | /* |
| 799 | * We created the item, then did a lookup, and found |
| 800 | * it was already linked to another inode we already |
Yan, Zheng | 4d41cef | 2015-02-04 15:10:48 +0800 | [diff] [blame] | 801 | * had in our cache (and thus got spliced). To not |
| 802 | * confuse VFS (especially when inode is a directory), |
| 803 | * we don't link our dentry to that inode, return an |
| 804 | * error instead. |
| 805 | * |
| 806 | * This event should be rare and it happens only when |
| 807 | * we talk to old MDS. Recent MDS does not send traceless |
| 808 | * reply for request that creates new inode. |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 809 | */ |
Yan, Zheng | 5cba372 | 2015-02-02 11:27:56 +0800 | [diff] [blame] | 810 | d_drop(result); |
Yan, Zheng | 4d41cef | 2015-02-04 15:10:48 +0800 | [diff] [blame] | 811 | return -ESTALE; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 812 | } |
| 813 | return PTR_ERR(result); |
| 814 | } |
| 815 | |
| 816 | static int ceph_mknod(struct inode *dir, struct dentry *dentry, |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 817 | umode_t mode, dev_t rdev) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 818 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 819 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 820 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 821 | struct ceph_mds_request *req; |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 822 | struct ceph_acls_info acls = {}; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 823 | int err; |
| 824 | |
| 825 | if (ceph_snap(dir) != CEPH_NOSNAP) |
| 826 | return -EROFS; |
| 827 | |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 828 | err = ceph_pre_init_acls(dir, &mode, &acls); |
| 829 | if (err < 0) |
| 830 | return err; |
| 831 | |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 832 | dout("mknod in dir %p dentry %p mode 0%ho rdev %d\n", |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 833 | dir, dentry, mode, rdev); |
| 834 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, USE_AUTH_MDS); |
| 835 | if (IS_ERR(req)) { |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 836 | err = PTR_ERR(req); |
| 837 | goto out; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 838 | } |
| 839 | req->r_dentry = dget(dentry); |
| 840 | req->r_num_caps = 2; |
| 841 | req->r_locked_dir = dir; |
| 842 | req->r_args.mknod.mode = cpu_to_le32(mode); |
| 843 | req->r_args.mknod.rdev = cpu_to_le32(rdev); |
| 844 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 845 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 846 | if (acls.pagelist) { |
| 847 | req->r_pagelist = acls.pagelist; |
| 848 | acls.pagelist = NULL; |
| 849 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 850 | err = ceph_mdsc_do_request(mdsc, dir, req); |
| 851 | if (!err && !req->r_reply_info.head->is_dentry) |
| 852 | err = ceph_handle_notrace_create(dir, dentry); |
| 853 | ceph_mdsc_put_request(req); |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 854 | out: |
Guangliang Zhao | 7221fe4 | 2013-11-11 15:18:03 +0800 | [diff] [blame] | 855 | if (!err) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 856 | ceph_init_inode_acls(d_inode(dentry), &acls); |
Yan, Zheng | b20a95a | 2014-02-11 12:55:05 +0800 | [diff] [blame] | 857 | else |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 858 | d_drop(dentry); |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 859 | ceph_release_acls_info(&acls); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 860 | return err; |
| 861 | } |
| 862 | |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 863 | static int ceph_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 864 | bool excl) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 865 | { |
Miklos Szeredi | 2d83bde | 2012-06-05 15:10:25 +0200 | [diff] [blame] | 866 | return ceph_mknod(dir, dentry, mode, 0); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static int ceph_symlink(struct inode *dir, struct dentry *dentry, |
| 870 | const char *dest) |
| 871 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 872 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 873 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 874 | struct ceph_mds_request *req; |
| 875 | int err; |
| 876 | |
| 877 | if (ceph_snap(dir) != CEPH_NOSNAP) |
| 878 | return -EROFS; |
| 879 | |
| 880 | dout("symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest); |
| 881 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, USE_AUTH_MDS); |
| 882 | if (IS_ERR(req)) { |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 883 | err = PTR_ERR(req); |
| 884 | goto out; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 885 | } |
Yan, Zheng | 687265e | 2015-06-13 17:27:05 +0800 | [diff] [blame] | 886 | req->r_path2 = kstrdup(dest, GFP_KERNEL); |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 887 | if (!req->r_path2) { |
| 888 | err = -ENOMEM; |
| 889 | ceph_mdsc_put_request(req); |
| 890 | goto out; |
| 891 | } |
| 892 | req->r_locked_dir = dir; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 893 | req->r_dentry = dget(dentry); |
| 894 | req->r_num_caps = 2; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 895 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 896 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
| 897 | err = ceph_mdsc_do_request(mdsc, dir, req); |
| 898 | if (!err && !req->r_reply_info.head->is_dentry) |
| 899 | err = ceph_handle_notrace_create(dir, dentry); |
| 900 | ceph_mdsc_put_request(req); |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 901 | out: |
| 902 | if (err) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 903 | d_drop(dentry); |
| 904 | return err; |
| 905 | } |
| 906 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 907 | static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 908 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 909 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 910 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 911 | struct ceph_mds_request *req; |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 912 | struct ceph_acls_info acls = {}; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 913 | int err = -EROFS; |
| 914 | int op; |
| 915 | |
| 916 | if (ceph_snap(dir) == CEPH_SNAPDIR) { |
| 917 | /* mkdir .snap/foo is a MKSNAP */ |
| 918 | op = CEPH_MDS_OP_MKSNAP; |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 919 | dout("mksnap dir %p snap '%pd' dn %p\n", dir, |
| 920 | dentry, dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 921 | } else if (ceph_snap(dir) == CEPH_NOSNAP) { |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 922 | dout("mkdir dir %p dn %p mode 0%ho\n", dir, dentry, mode); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 923 | op = CEPH_MDS_OP_MKDIR; |
| 924 | } else { |
| 925 | goto out; |
| 926 | } |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 927 | |
| 928 | mode |= S_IFDIR; |
| 929 | err = ceph_pre_init_acls(dir, &mode, &acls); |
| 930 | if (err < 0) |
| 931 | goto out; |
| 932 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 933 | req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); |
| 934 | if (IS_ERR(req)) { |
| 935 | err = PTR_ERR(req); |
| 936 | goto out; |
| 937 | } |
| 938 | |
| 939 | req->r_dentry = dget(dentry); |
| 940 | req->r_num_caps = 2; |
| 941 | req->r_locked_dir = dir; |
| 942 | req->r_args.mkdir.mode = cpu_to_le32(mode); |
| 943 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 944 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 945 | if (acls.pagelist) { |
| 946 | req->r_pagelist = acls.pagelist; |
| 947 | acls.pagelist = NULL; |
| 948 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 949 | err = ceph_mdsc_do_request(mdsc, dir, req); |
Yan, Zheng | 275dd19 | 2014-12-10 16:17:31 +0800 | [diff] [blame] | 950 | if (!err && |
| 951 | !req->r_reply_info.head->is_target && |
| 952 | !req->r_reply_info.head->is_dentry) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 953 | err = ceph_handle_notrace_create(dir, dentry); |
| 954 | ceph_mdsc_put_request(req); |
| 955 | out: |
Yan, Zheng | b20a95a | 2014-02-11 12:55:05 +0800 | [diff] [blame] | 956 | if (!err) |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 957 | ceph_init_inode_acls(d_inode(dentry), &acls); |
Yan, Zheng | b20a95a | 2014-02-11 12:55:05 +0800 | [diff] [blame] | 958 | else |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 959 | d_drop(dentry); |
Yan, Zheng | b1ee94a | 2014-09-16 20:35:17 +0800 | [diff] [blame] | 960 | ceph_release_acls_info(&acls); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 961 | return err; |
| 962 | } |
| 963 | |
| 964 | static int ceph_link(struct dentry *old_dentry, struct inode *dir, |
| 965 | struct dentry *dentry) |
| 966 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 967 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 968 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 969 | struct ceph_mds_request *req; |
| 970 | int err; |
| 971 | |
| 972 | if (ceph_snap(dir) != CEPH_NOSNAP) |
| 973 | return -EROFS; |
| 974 | |
| 975 | dout("link in dir %p old_dentry %p dentry %p\n", dir, |
| 976 | old_dentry, dentry); |
| 977 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LINK, USE_AUTH_MDS); |
| 978 | if (IS_ERR(req)) { |
| 979 | d_drop(dentry); |
| 980 | return PTR_ERR(req); |
| 981 | } |
| 982 | req->r_dentry = dget(dentry); |
| 983 | req->r_num_caps = 2; |
Sage Weil | 4b58c9b | 2013-02-05 13:41:23 -0800 | [diff] [blame] | 984 | req->r_old_dentry = dget(old_dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 985 | req->r_locked_dir = dir; |
| 986 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 987 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
Yan, Zheng | ad88f23 | 2013-07-21 20:25:25 +0800 | [diff] [blame] | 988 | /* release LINK_SHARED on source inode (mds will lock it) */ |
| 989 | req->r_old_inode_drop = CEPH_CAP_LINK_SHARED; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 990 | err = ceph_mdsc_do_request(mdsc, dir, req); |
Sage Weil | 70b666c | 2011-05-27 09:24:26 -0700 | [diff] [blame] | 991 | if (err) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 992 | d_drop(dentry); |
Sage Weil | 70b666c | 2011-05-27 09:24:26 -0700 | [diff] [blame] | 993 | } else if (!req->r_reply_info.head->is_dentry) { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 994 | ihold(d_inode(old_dentry)); |
| 995 | d_instantiate(dentry, d_inode(old_dentry)); |
Sage Weil | 70b666c | 2011-05-27 09:24:26 -0700 | [diff] [blame] | 996 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 997 | ceph_mdsc_put_request(req); |
| 998 | return err; |
| 999 | } |
| 1000 | |
| 1001 | /* |
| 1002 | * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it |
| 1003 | * looks like the link count will hit 0, drop any other caps (other |
| 1004 | * than PIN) we don't specifically want (due to the file still being |
| 1005 | * open). |
| 1006 | */ |
| 1007 | static int drop_caps_for_unlink(struct inode *inode) |
| 1008 | { |
| 1009 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 1010 | int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; |
| 1011 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1012 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1013 | if (inode->i_nlink == 1) { |
| 1014 | drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN); |
| 1015 | ci->i_ceph_flags |= CEPH_I_NODELAY; |
| 1016 | } |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1017 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1018 | return drop; |
| 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | * rmdir and unlink are differ only by the metadata op code |
| 1023 | */ |
| 1024 | static int ceph_unlink(struct inode *dir, struct dentry *dentry) |
| 1025 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1026 | struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); |
| 1027 | struct ceph_mds_client *mdsc = fsc->mdsc; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1028 | struct inode *inode = d_inode(dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1029 | struct ceph_mds_request *req; |
| 1030 | int err = -EROFS; |
| 1031 | int op; |
| 1032 | |
| 1033 | if (ceph_snap(dir) == CEPH_SNAPDIR) { |
| 1034 | /* rmdir .snap/foo is RMSNAP */ |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1035 | dout("rmsnap dir %p '%pd' dn %p\n", dir, dentry, dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1036 | op = CEPH_MDS_OP_RMSNAP; |
| 1037 | } else if (ceph_snap(dir) == CEPH_NOSNAP) { |
| 1038 | dout("unlink/rmdir dir %p dn %p inode %p\n", |
| 1039 | dir, dentry, inode); |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 1040 | op = d_is_dir(dentry) ? |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1041 | CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK; |
| 1042 | } else |
| 1043 | goto out; |
| 1044 | req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); |
| 1045 | if (IS_ERR(req)) { |
| 1046 | err = PTR_ERR(req); |
| 1047 | goto out; |
| 1048 | } |
| 1049 | req->r_dentry = dget(dentry); |
| 1050 | req->r_num_caps = 2; |
| 1051 | req->r_locked_dir = dir; |
| 1052 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 1053 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
| 1054 | req->r_inode_drop = drop_caps_for_unlink(inode); |
| 1055 | err = ceph_mdsc_do_request(mdsc, dir, req); |
| 1056 | if (!err && !req->r_reply_info.head->is_dentry) |
| 1057 | d_delete(dentry); |
| 1058 | ceph_mdsc_put_request(req); |
| 1059 | out: |
| 1060 | return err; |
| 1061 | } |
| 1062 | |
| 1063 | static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1064 | struct inode *new_dir, struct dentry *new_dentry) |
| 1065 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1066 | struct ceph_fs_client *fsc = ceph_sb_to_client(old_dir->i_sb); |
| 1067 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1068 | struct ceph_mds_request *req; |
Yan, Zheng | 0ea611a | 2015-04-07 15:36:32 +0800 | [diff] [blame] | 1069 | int op = CEPH_MDS_OP_RENAME; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1070 | int err; |
| 1071 | |
| 1072 | if (ceph_snap(old_dir) != ceph_snap(new_dir)) |
| 1073 | return -EXDEV; |
Yan, Zheng | 0ea611a | 2015-04-07 15:36:32 +0800 | [diff] [blame] | 1074 | if (ceph_snap(old_dir) != CEPH_NOSNAP) { |
| 1075 | if (old_dir == new_dir && ceph_snap(old_dir) == CEPH_SNAPDIR) |
| 1076 | op = CEPH_MDS_OP_RENAMESNAP; |
| 1077 | else |
| 1078 | return -EROFS; |
| 1079 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1080 | dout("rename dir %p dentry %p to dir %p dentry %p\n", |
| 1081 | old_dir, old_dentry, new_dir, new_dentry); |
Yan, Zheng | 0ea611a | 2015-04-07 15:36:32 +0800 | [diff] [blame] | 1082 | req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1083 | if (IS_ERR(req)) |
| 1084 | return PTR_ERR(req); |
Sage Weil | 180061a | 2013-02-05 13:36:05 -0800 | [diff] [blame] | 1085 | ihold(old_dir); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1086 | req->r_dentry = dget(new_dentry); |
| 1087 | req->r_num_caps = 2; |
| 1088 | req->r_old_dentry = dget(old_dentry); |
Sage Weil | 180061a | 2013-02-05 13:36:05 -0800 | [diff] [blame] | 1089 | req->r_old_dentry_dir = old_dir; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1090 | req->r_locked_dir = new_dir; |
| 1091 | req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 1092 | req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL; |
| 1093 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
| 1094 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
| 1095 | /* release LINK_RDCACHE on source inode (mds will lock it) */ |
| 1096 | req->r_old_inode_drop = CEPH_CAP_LINK_SHARED; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1097 | if (d_really_is_positive(new_dentry)) |
| 1098 | req->r_inode_drop = drop_caps_for_unlink(d_inode(new_dentry)); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1099 | err = ceph_mdsc_do_request(mdsc, old_dir, req); |
| 1100 | if (!err && !req->r_reply_info.head->is_dentry) { |
| 1101 | /* |
| 1102 | * Normally d_move() is done by fill_trace (called by |
| 1103 | * do_request, above). If there is no trace, we need |
| 1104 | * to do it here. |
| 1105 | */ |
Sage Weil | ea1409f | 2010-04-28 16:12:06 -0700 | [diff] [blame] | 1106 | |
Yan, Zheng | fdd4e15 | 2015-06-16 20:48:56 +0800 | [diff] [blame] | 1107 | /* d_move screws up sibling dentries' offsets */ |
| 1108 | ceph_dir_clear_complete(old_dir); |
| 1109 | ceph_dir_clear_complete(new_dir); |
| 1110 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1111 | d_move(old_dentry, new_dentry); |
Sage Weil | ea1409f | 2010-04-28 16:12:06 -0700 | [diff] [blame] | 1112 | |
| 1113 | /* ensure target dentry is invalidated, despite |
| 1114 | rehashing bug in vfs_rename_dir */ |
Sage Weil | 81a6cf2 | 2010-05-14 09:35:38 -0700 | [diff] [blame] | 1115 | ceph_invalidate_dentry_lease(new_dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1116 | } |
| 1117 | ceph_mdsc_put_request(req); |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
Sage Weil | 81a6cf2 | 2010-05-14 09:35:38 -0700 | [diff] [blame] | 1121 | /* |
| 1122 | * Ensure a dentry lease will no longer revalidate. |
| 1123 | */ |
| 1124 | void ceph_invalidate_dentry_lease(struct dentry *dentry) |
| 1125 | { |
| 1126 | spin_lock(&dentry->d_lock); |
Miklos Szeredi | 9b16f03c | 2016-06-22 16:35:04 +0200 | [diff] [blame] | 1127 | ceph_dentry(dentry)->time = jiffies; |
Sage Weil | 81a6cf2 | 2010-05-14 09:35:38 -0700 | [diff] [blame] | 1128 | ceph_dentry(dentry)->lease_shared_gen = 0; |
| 1129 | spin_unlock(&dentry->d_lock); |
| 1130 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * Check if dentry lease is valid. If not, delete the lease. Try to |
| 1134 | * renew if the least is more than half up. |
| 1135 | */ |
Jeff Layton | 14fb9c9 | 2016-07-01 09:39:20 -0400 | [diff] [blame] | 1136 | static int dentry_lease_is_valid(struct dentry *dentry, unsigned int flags, |
| 1137 | struct inode *dir) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1138 | { |
| 1139 | struct ceph_dentry_info *di; |
| 1140 | struct ceph_mds_session *s; |
| 1141 | int valid = 0; |
| 1142 | u32 gen; |
| 1143 | unsigned long ttl; |
| 1144 | struct ceph_mds_session *session = NULL; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1145 | u32 seq = 0; |
| 1146 | |
| 1147 | spin_lock(&dentry->d_lock); |
| 1148 | di = ceph_dentry(dentry); |
Jeff Layton | 14fb9c9 | 2016-07-01 09:39:20 -0400 | [diff] [blame] | 1149 | if (di && di->lease_session) { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1150 | s = di->lease_session; |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 1151 | spin_lock(&s->s_gen_ttl_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1152 | gen = s->s_cap_gen; |
| 1153 | ttl = s->s_cap_ttl; |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 1154 | spin_unlock(&s->s_gen_ttl_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1155 | |
| 1156 | if (di->lease_gen == gen && |
Miklos Szeredi | 9b16f03c | 2016-06-22 16:35:04 +0200 | [diff] [blame] | 1157 | time_before(jiffies, di->time) && |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1158 | time_before(jiffies, ttl)) { |
| 1159 | valid = 1; |
| 1160 | if (di->lease_renew_after && |
| 1161 | time_after(jiffies, di->lease_renew_after)) { |
Jeff Layton | 14fb9c9 | 2016-07-01 09:39:20 -0400 | [diff] [blame] | 1162 | /* |
| 1163 | * We should renew. If we're in RCU walk mode |
| 1164 | * though, we can't do that so just return |
| 1165 | * -ECHILD. |
| 1166 | */ |
| 1167 | if (flags & LOOKUP_RCU) { |
| 1168 | valid = -ECHILD; |
| 1169 | } else { |
| 1170 | session = ceph_get_mds_session(s); |
| 1171 | seq = di->lease_seq; |
| 1172 | di->lease_renew_after = 0; |
| 1173 | di->lease_renew_from = jiffies; |
| 1174 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1175 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | spin_unlock(&dentry->d_lock); |
| 1179 | |
| 1180 | if (session) { |
| 1181 | ceph_mdsc_lease_send_msg(session, dir, dentry, |
| 1182 | CEPH_MDS_LEASE_RENEW, seq); |
| 1183 | ceph_put_mds_session(session); |
| 1184 | } |
| 1185 | dout("dentry_lease_is_valid - dentry %p = %d\n", dentry, valid); |
| 1186 | return valid; |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * Check if directory-wide content lease/cap is valid. |
| 1191 | */ |
| 1192 | static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry) |
| 1193 | { |
| 1194 | struct ceph_inode_info *ci = ceph_inode(dir); |
| 1195 | struct ceph_dentry_info *di = ceph_dentry(dentry); |
| 1196 | int valid = 0; |
| 1197 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1198 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1199 | if (ci->i_shared_gen == di->lease_shared_gen) |
| 1200 | valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1); |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1201 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1202 | dout("dir_lease_is_valid dir %p v%u dentry %p v%u = %d\n", |
| 1203 | dir, (unsigned)ci->i_shared_gen, dentry, |
| 1204 | (unsigned)di->lease_shared_gen, valid); |
| 1205 | return valid; |
| 1206 | } |
| 1207 | |
| 1208 | /* |
| 1209 | * Check if cached dentry can be trusted. |
| 1210 | */ |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1211 | static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1212 | { |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1213 | int valid = 0; |
Yan, Zheng | 641235d | 2016-03-16 16:40:23 +0800 | [diff] [blame] | 1214 | struct dentry *parent; |
Nick Piggin | 34286d6 | 2011-01-07 17:49:57 +1100 | [diff] [blame] | 1215 | struct inode *dir; |
| 1216 | |
Jeff Layton | f49d1e0 | 2016-07-01 09:39:21 -0400 | [diff] [blame] | 1217 | if (flags & LOOKUP_RCU) { |
| 1218 | parent = ACCESS_ONCE(dentry->d_parent); |
| 1219 | dir = d_inode_rcu(parent); |
| 1220 | if (!dir) |
| 1221 | return -ECHILD; |
| 1222 | } else { |
| 1223 | parent = dget_parent(dentry); |
| 1224 | dir = d_inode(parent); |
| 1225 | } |
Nick Piggin | 34286d6 | 2011-01-07 17:49:57 +1100 | [diff] [blame] | 1226 | |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1227 | dout("d_revalidate %p '%pd' inode %p offset %lld\n", dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1228 | dentry, d_inode(dentry), ceph_dentry(dentry)->offset); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* always trust cached snapped dentries, snapdir dentry */ |
| 1231 | if (ceph_snap(dir) != CEPH_NOSNAP) { |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1232 | dout("d_revalidate %p '%pd' inode %p is SNAPPED\n", dentry, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1233 | dentry, d_inode(dentry)); |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1234 | valid = 1; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1235 | } else if (d_really_is_positive(dentry) && |
| 1236 | ceph_snap(d_inode(dentry)) == CEPH_SNAPDIR) { |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1237 | valid = 1; |
Jeff Layton | 14fb9c9 | 2016-07-01 09:39:20 -0400 | [diff] [blame] | 1238 | } else { |
| 1239 | valid = dentry_lease_is_valid(dentry, flags, dir); |
| 1240 | if (valid == -ECHILD) |
| 1241 | return valid; |
| 1242 | if (valid || dir_lease_is_valid(dir, dentry)) { |
| 1243 | if (d_really_is_positive(dentry)) |
| 1244 | valid = ceph_is_any_caps(d_inode(dentry)); |
| 1245 | else |
| 1246 | valid = 1; |
| 1247 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1248 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1249 | |
Yan, Zheng | 200fd27 | 2016-03-17 14:41:59 +0800 | [diff] [blame] | 1250 | if (!valid) { |
| 1251 | struct ceph_mds_client *mdsc = |
| 1252 | ceph_sb_to_client(dir->i_sb)->mdsc; |
| 1253 | struct ceph_mds_request *req; |
| 1254 | int op, mask, err; |
| 1255 | |
Jeff Layton | f49d1e0 | 2016-07-01 09:39:21 -0400 | [diff] [blame] | 1256 | if (flags & LOOKUP_RCU) |
| 1257 | return -ECHILD; |
| 1258 | |
Yan, Zheng | 200fd27 | 2016-03-17 14:41:59 +0800 | [diff] [blame] | 1259 | op = ceph_snap(dir) == CEPH_SNAPDIR ? |
| 1260 | CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP; |
| 1261 | req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS); |
| 1262 | if (!IS_ERR(req)) { |
| 1263 | req->r_dentry = dget(dentry); |
| 1264 | req->r_num_caps = 2; |
| 1265 | |
| 1266 | mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED; |
| 1267 | if (ceph_security_xattr_wanted(dir)) |
| 1268 | mask |= CEPH_CAP_XATTR_SHARED; |
| 1269 | req->r_args.getattr.mask = mask; |
| 1270 | |
| 1271 | req->r_locked_dir = dir; |
| 1272 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
| 1273 | if (err == 0 || err == -ENOENT) { |
| 1274 | if (dentry == req->r_dentry) { |
| 1275 | valid = !d_unhashed(dentry); |
| 1276 | } else { |
| 1277 | d_invalidate(req->r_dentry); |
| 1278 | err = -EAGAIN; |
| 1279 | } |
| 1280 | } |
| 1281 | ceph_mdsc_put_request(req); |
| 1282 | dout("d_revalidate %p lookup result=%d\n", |
| 1283 | dentry, err); |
| 1284 | } |
| 1285 | } |
| 1286 | |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1287 | dout("d_revalidate %p %s\n", dentry, valid ? "valid" : "invalid"); |
Yan, Zheng | 9215aee | 2013-11-30 12:47:41 +0800 | [diff] [blame] | 1288 | if (valid) { |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1289 | ceph_dentry_lru_touch(dentry); |
Yan, Zheng | 9215aee | 2013-11-30 12:47:41 +0800 | [diff] [blame] | 1290 | } else { |
| 1291 | ceph_dir_clear_complete(dir); |
Yan, Zheng | 9215aee | 2013-11-30 12:47:41 +0800 | [diff] [blame] | 1292 | } |
Yan, Zheng | 641235d | 2016-03-16 16:40:23 +0800 | [diff] [blame] | 1293 | |
Jeff Layton | f49d1e0 | 2016-07-01 09:39:21 -0400 | [diff] [blame] | 1294 | if (!(flags & LOOKUP_RCU)) |
| 1295 | dput(parent); |
Sage Weil | bf1c6ac | 2011-07-26 11:30:43 -0700 | [diff] [blame] | 1296 | return valid; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /* |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1300 | * Release our ceph_dentry_info. |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1301 | */ |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1302 | static void ceph_d_release(struct dentry *dentry) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1303 | { |
| 1304 | struct ceph_dentry_info *di = ceph_dentry(dentry); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1305 | |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1306 | dout("d_release %p\n", dentry); |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 1307 | ceph_dentry_lru_del(dentry); |
Jeff Layton | 5b484a5 | 2016-07-01 09:39:20 -0400 | [diff] [blame] | 1308 | |
| 1309 | spin_lock(&dentry->d_lock); |
| 1310 | dentry->d_fsdata = NULL; |
| 1311 | spin_unlock(&dentry->d_lock); |
| 1312 | |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 1313 | if (di->lease_session) |
| 1314 | ceph_put_mds_session(di->lease_session); |
| 1315 | kmem_cache_free(ceph_dentry_cachep, di); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | static int ceph_snapdir_d_revalidate(struct dentry *dentry, |
Al Viro | 0b728e1 | 2012-06-10 16:03:43 -0400 | [diff] [blame] | 1319 | unsigned int flags) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1320 | { |
| 1321 | /* |
| 1322 | * Eventually, we'll want to revalidate snapped metadata |
| 1323 | * too... probably... |
| 1324 | */ |
| 1325 | return 1; |
| 1326 | } |
| 1327 | |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1328 | /* |
| 1329 | * When the VFS prunes a dentry from the cache, we need to clear the |
| 1330 | * complete flag on the parent directory. |
| 1331 | * |
| 1332 | * Called under dentry->d_lock. |
| 1333 | */ |
| 1334 | static void ceph_d_prune(struct dentry *dentry) |
| 1335 | { |
Sage Weil | 774ac21 | 2011-11-11 09:48:08 -0800 | [diff] [blame] | 1336 | dout("ceph_d_prune %p\n", dentry); |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1337 | |
| 1338 | /* do we have a valid parent? */ |
Sage Weil | 8842b3b | 2012-06-07 13:43:35 -0700 | [diff] [blame] | 1339 | if (IS_ROOT(dentry)) |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1340 | return; |
| 1341 | |
Yan, Zheng | 2f276c5 | 2013-03-13 19:44:32 +0800 | [diff] [blame] | 1342 | /* if we are not hashed, we don't affect dir's completeness */ |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1343 | if (d_unhashed(dentry)) |
| 1344 | return; |
| 1345 | |
| 1346 | /* |
| 1347 | * we hold d_lock, so d_parent is stable, and d_fsdata is never |
| 1348 | * cleared until d_release |
| 1349 | */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1350 | ceph_dir_clear_complete(d_inode(dentry->d_parent)); |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1351 | } |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1352 | |
| 1353 | /* |
| 1354 | * read() on a dir. This weird interface hack only works if mounted |
| 1355 | * with '-o dirstat'. |
| 1356 | */ |
| 1357 | static ssize_t ceph_read_dir(struct file *file, char __user *buf, size_t size, |
| 1358 | loff_t *ppos) |
| 1359 | { |
| 1360 | struct ceph_file_info *cf = file->private_data; |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1361 | struct inode *inode = file_inode(file); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1362 | struct ceph_inode_info *ci = ceph_inode(inode); |
| 1363 | int left; |
Sage Weil | ae59808 | 2011-05-12 14:28:05 -0700 | [diff] [blame] | 1364 | const int bufsize = 1024; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1365 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1366 | if (!ceph_test_mount_opt(ceph_sb_to_client(inode->i_sb), DIRSTAT)) |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1367 | return -EISDIR; |
| 1368 | |
| 1369 | if (!cf->dir_info) { |
Yan, Zheng | 687265e | 2015-06-13 17:27:05 +0800 | [diff] [blame] | 1370 | cf->dir_info = kmalloc(bufsize, GFP_KERNEL); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1371 | if (!cf->dir_info) |
| 1372 | return -ENOMEM; |
| 1373 | cf->dir_info_len = |
Sage Weil | ae59808 | 2011-05-12 14:28:05 -0700 | [diff] [blame] | 1374 | snprintf(cf->dir_info, bufsize, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1375 | "entries: %20lld\n" |
| 1376 | " files: %20lld\n" |
| 1377 | " subdirs: %20lld\n" |
| 1378 | "rentries: %20lld\n" |
| 1379 | " rfiles: %20lld\n" |
| 1380 | " rsubdirs: %20lld\n" |
| 1381 | "rbytes: %20lld\n" |
| 1382 | "rctime: %10ld.%09ld\n", |
| 1383 | ci->i_files + ci->i_subdirs, |
| 1384 | ci->i_files, |
| 1385 | ci->i_subdirs, |
| 1386 | ci->i_rfiles + ci->i_rsubdirs, |
| 1387 | ci->i_rfiles, |
| 1388 | ci->i_rsubdirs, |
| 1389 | ci->i_rbytes, |
| 1390 | (long)ci->i_rctime.tv_sec, |
| 1391 | (long)ci->i_rctime.tv_nsec); |
| 1392 | } |
| 1393 | |
| 1394 | if (*ppos >= cf->dir_info_len) |
| 1395 | return 0; |
| 1396 | size = min_t(unsigned, size, cf->dir_info_len-*ppos); |
| 1397 | left = copy_to_user(buf, cf->dir_info + *ppos, size); |
| 1398 | if (left == size) |
| 1399 | return -EFAULT; |
| 1400 | *ppos += (size - left); |
| 1401 | return size - left; |
| 1402 | } |
| 1403 | |
| 1404 | /* |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1405 | * We maintain a private dentry LRU. |
| 1406 | * |
| 1407 | * FIXME: this needs to be changed to a per-mds lru to be useful. |
| 1408 | */ |
| 1409 | void ceph_dentry_lru_add(struct dentry *dn) |
| 1410 | { |
| 1411 | struct ceph_dentry_info *di = ceph_dentry(dn); |
| 1412 | struct ceph_mds_client *mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1413 | |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1414 | dout("dentry_lru_add %p %p '%pd'\n", di, dn, dn); |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 1415 | mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; |
| 1416 | spin_lock(&mdsc->dentry_lru_lock); |
| 1417 | list_add_tail(&di->lru, &mdsc->dentry_lru); |
| 1418 | mdsc->num_dentry++; |
| 1419 | spin_unlock(&mdsc->dentry_lru_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | void ceph_dentry_lru_touch(struct dentry *dn) |
| 1423 | { |
| 1424 | struct ceph_dentry_info *di = ceph_dentry(dn); |
| 1425 | struct ceph_mds_client *mdsc; |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1426 | |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1427 | dout("dentry_lru_touch %p %p '%pd' (offset %lld)\n", di, dn, dn, |
| 1428 | di->offset); |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 1429 | mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; |
| 1430 | spin_lock(&mdsc->dentry_lru_lock); |
| 1431 | list_move_tail(&di->lru, &mdsc->dentry_lru); |
| 1432 | spin_unlock(&mdsc->dentry_lru_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | void ceph_dentry_lru_del(struct dentry *dn) |
| 1436 | { |
| 1437 | struct ceph_dentry_info *di = ceph_dentry(dn); |
| 1438 | struct ceph_mds_client *mdsc; |
| 1439 | |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 1440 | dout("dentry_lru_del %p %p '%pd'\n", di, dn, dn); |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 1441 | mdsc = ceph_sb_to_client(dn->d_sb)->mdsc; |
| 1442 | spin_lock(&mdsc->dentry_lru_lock); |
| 1443 | list_del_init(&di->lru); |
| 1444 | mdsc->num_dentry--; |
| 1445 | spin_unlock(&mdsc->dentry_lru_lock); |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Sage Weil | 6c0f3af | 2010-11-16 11:14:34 -0800 | [diff] [blame] | 1448 | /* |
| 1449 | * Return name hash for a given dentry. This is dependent on |
| 1450 | * the parent directory's hash function. |
| 1451 | */ |
Sage Weil | e5f86dc | 2011-07-26 11:30:55 -0700 | [diff] [blame] | 1452 | unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn) |
Sage Weil | 6c0f3af | 2010-11-16 11:14:34 -0800 | [diff] [blame] | 1453 | { |
Sage Weil | 6c0f3af | 2010-11-16 11:14:34 -0800 | [diff] [blame] | 1454 | struct ceph_inode_info *dci = ceph_inode(dir); |
| 1455 | |
| 1456 | switch (dci->i_dir_layout.dl_dir_hash) { |
| 1457 | case 0: /* for backward compat */ |
| 1458 | case CEPH_STR_HASH_LINUX: |
| 1459 | return dn->d_name.hash; |
| 1460 | |
| 1461 | default: |
| 1462 | return ceph_str_hash(dci->i_dir_layout.dl_dir_hash, |
| 1463 | dn->d_name.name, dn->d_name.len); |
| 1464 | } |
| 1465 | } |
| 1466 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1467 | const struct file_operations ceph_dir_fops = { |
| 1468 | .read = ceph_read_dir, |
Al Viro | 77acfa2 | 2013-05-17 16:52:26 -0400 | [diff] [blame] | 1469 | .iterate = ceph_readdir, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1470 | .llseek = ceph_dir_llseek, |
| 1471 | .open = ceph_open, |
| 1472 | .release = ceph_release, |
| 1473 | .unlocked_ioctl = ceph_ioctl, |
Yan, Zheng | da819c8 | 2015-05-27 11:19:34 +0800 | [diff] [blame] | 1474 | .fsync = ceph_fsync, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1475 | }; |
| 1476 | |
Yan, Zheng | 38c48b5 | 2015-01-14 13:46:04 +0800 | [diff] [blame] | 1477 | const struct file_operations ceph_snapdir_fops = { |
| 1478 | .iterate = ceph_readdir, |
| 1479 | .llseek = ceph_dir_llseek, |
| 1480 | .open = ceph_open, |
| 1481 | .release = ceph_release, |
| 1482 | }; |
| 1483 | |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1484 | const struct inode_operations ceph_dir_iops = { |
| 1485 | .lookup = ceph_lookup, |
| 1486 | .permission = ceph_permission, |
| 1487 | .getattr = ceph_getattr, |
| 1488 | .setattr = ceph_setattr, |
Andreas Gruenbacher | 2cdeb1e | 2016-04-14 00:30:17 +0200 | [diff] [blame] | 1489 | .setxattr = generic_setxattr, |
| 1490 | .getxattr = generic_getxattr, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1491 | .listxattr = ceph_listxattr, |
Andreas Gruenbacher | 2cdeb1e | 2016-04-14 00:30:17 +0200 | [diff] [blame] | 1492 | .removexattr = generic_removexattr, |
Guangliang Zhao | 7221fe4 | 2013-11-11 15:18:03 +0800 | [diff] [blame] | 1493 | .get_acl = ceph_get_acl, |
Sage Weil | 72466d0 | 2014-01-29 06:22:25 -0800 | [diff] [blame] | 1494 | .set_acl = ceph_set_acl, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1495 | .mknod = ceph_mknod, |
| 1496 | .symlink = ceph_symlink, |
| 1497 | .mkdir = ceph_mkdir, |
| 1498 | .link = ceph_link, |
| 1499 | .unlink = ceph_unlink, |
| 1500 | .rmdir = ceph_unlink, |
| 1501 | .rename = ceph_rename, |
| 1502 | .create = ceph_create, |
Miklos Szeredi | 2d83bde | 2012-06-05 15:10:25 +0200 | [diff] [blame] | 1503 | .atomic_open = ceph_atomic_open, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1504 | }; |
| 1505 | |
Yan, Zheng | 38c48b5 | 2015-01-14 13:46:04 +0800 | [diff] [blame] | 1506 | const struct inode_operations ceph_snapdir_iops = { |
| 1507 | .lookup = ceph_lookup, |
| 1508 | .permission = ceph_permission, |
| 1509 | .getattr = ceph_getattr, |
| 1510 | .mkdir = ceph_mkdir, |
| 1511 | .rmdir = ceph_unlink, |
Yan, Zheng | 0ea611a | 2015-04-07 15:36:32 +0800 | [diff] [blame] | 1512 | .rename = ceph_rename, |
Yan, Zheng | 38c48b5 | 2015-01-14 13:46:04 +0800 | [diff] [blame] | 1513 | }; |
| 1514 | |
Sage Weil | 52dfb8a | 2010-08-03 10:25:30 -0700 | [diff] [blame] | 1515 | const struct dentry_operations ceph_dentry_ops = { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1516 | .d_revalidate = ceph_d_revalidate, |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1517 | .d_release = ceph_d_release, |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1518 | .d_prune = ceph_d_prune, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1519 | }; |
| 1520 | |
Sage Weil | 52dfb8a | 2010-08-03 10:25:30 -0700 | [diff] [blame] | 1521 | const struct dentry_operations ceph_snapdir_dentry_ops = { |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1522 | .d_revalidate = ceph_snapdir_d_revalidate, |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1523 | .d_release = ceph_d_release, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1524 | }; |
| 1525 | |
Sage Weil | 52dfb8a | 2010-08-03 10:25:30 -0700 | [diff] [blame] | 1526 | const struct dentry_operations ceph_snap_dentry_ops = { |
Sage Weil | 147851d | 2011-03-15 14:57:41 -0700 | [diff] [blame] | 1527 | .d_release = ceph_d_release, |
Sage Weil | b58dc41 | 2011-03-15 15:53:40 -0700 | [diff] [blame] | 1528 | .d_prune = ceph_d_prune, |
Sage Weil | 2817b00 | 2009-10-06 11:31:08 -0700 | [diff] [blame] | 1529 | }; |