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