Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License version 2 for more details (a copy is included | |
14 | * in the LICENSE file that accompanied this code). | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * version 2 along with this program; If not, see | |
6a5b99a4 | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
d7e09d03 | 19 | * |
d7e09d03 PT |
20 | * GPL HEADER END |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. | |
24 | * Use is subject to license terms. | |
25 | * | |
1dc563a6 | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
27 | */ |
28 | /* | |
29 | * This file is part of Lustre, http://www.lustre.org/ | |
30 | * Lustre is a trademark of Sun Microsystems, Inc. | |
31 | */ | |
32 | ||
33 | #include <linux/fs.h> | |
34 | #include <linux/sched.h> | |
35 | #include <linux/mm.h> | |
36 | #include <linux/quotaops.h> | |
37 | #include <linux/highmem.h> | |
38 | #include <linux/pagemap.h> | |
39 | #include <linux/security.h> | |
40 | ||
41 | #define DEBUG_SUBSYSTEM S_LLITE | |
42 | ||
67a235f5 GKH |
43 | #include "../include/obd_support.h" |
44 | #include "../include/lustre_fid.h" | |
45 | #include "../include/lustre_lite.h" | |
46 | #include "../include/lustre_dlm.h" | |
47 | #include "../include/lustre_ver.h" | |
d7e09d03 PT |
48 | #include "llite_internal.h" |
49 | ||
50 | static int ll_create_it(struct inode *, struct dentry *, | |
51 | int, struct lookup_intent *); | |
52 | ||
5a3cd992 | 53 | /* called from iget5_locked->find_inode() under inode_hash_lock spinlock */ |
d7e09d03 PT |
54 | static int ll_test_inode(struct inode *inode, void *opaque) |
55 | { | |
56 | struct ll_inode_info *lli = ll_i2info(inode); | |
57 | struct lustre_md *md = opaque; | |
58 | ||
59 | if (unlikely(!(md->body->valid & OBD_MD_FLID))) { | |
60 | CERROR("MDS body missing FID\n"); | |
61 | return 0; | |
62 | } | |
63 | ||
64 | if (!lu_fid_eq(&lli->lli_fid, &md->body->fid1)) | |
65 | return 0; | |
66 | ||
67 | return 1; | |
68 | } | |
69 | ||
70 | static int ll_set_inode(struct inode *inode, void *opaque) | |
71 | { | |
72 | struct ll_inode_info *lli = ll_i2info(inode); | |
73 | struct mdt_body *body = ((struct lustre_md *)opaque)->body; | |
74 | ||
75 | if (unlikely(!(body->valid & OBD_MD_FLID))) { | |
76 | CERROR("MDS body missing FID\n"); | |
77 | return -EINVAL; | |
78 | } | |
79 | ||
80 | lli->lli_fid = body->fid1; | |
81 | if (unlikely(!(body->valid & OBD_MD_FLTYPE))) { | |
267d9c8a LM |
82 | CERROR("Can not initialize inode " DFID |
83 | " without object type: valid = %#llx\n", | |
2d00bd17 | 84 | PFID(&lli->lli_fid), body->valid); |
d7e09d03 PT |
85 | return -EINVAL; |
86 | } | |
87 | ||
88 | inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mode & S_IFMT); | |
89 | if (unlikely(inode->i_mode == 0)) { | |
90 | CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid)); | |
91 | return -EINVAL; | |
92 | } | |
93 | ||
94 | ll_lli_init(lli); | |
95 | ||
96 | return 0; | |
97 | } | |
98 | ||
d7e09d03 PT |
99 | /* |
100 | * Get an inode by inode number (already instantiated by the intent lookup). | |
101 | * Returns inode or NULL | |
102 | */ | |
103 | struct inode *ll_iget(struct super_block *sb, ino_t hash, | |
104 | struct lustre_md *md) | |
105 | { | |
106 | struct inode *inode; | |
d7e09d03 PT |
107 | |
108 | LASSERT(hash != 0); | |
109 | inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md); | |
110 | ||
111 | if (inode) { | |
112 | if (inode->i_state & I_NEW) { | |
113 | int rc = 0; | |
114 | ||
115 | ll_read_inode2(inode, md); | |
116 | if (S_ISREG(inode->i_mode) && | |
6e16818b | 117 | !ll_i2info(inode)->lli_clob) { |
d7e09d03 | 118 | CDEBUG(D_INODE, |
e15ba45d OD |
119 | "%s: apply lsm %p to inode " DFID ".\n", |
120 | ll_get_fsname(sb, NULL, 0), md->lsm, | |
121 | PFID(ll_inode2fid(inode))); | |
d7e09d03 PT |
122 | rc = cl_file_inode_init(inode, md); |
123 | } | |
124 | if (rc != 0) { | |
0e81ba23 | 125 | iget_failed(inode); |
020ecc6f | 126 | inode = NULL; |
da5ecb4d | 127 | } else { |
d7e09d03 | 128 | unlock_new_inode(inode); |
da5ecb4d OD |
129 | } |
130 | } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) { | |
d7e09d03 | 131 | ll_update_inode(inode, md); |
97a075cd JN |
132 | CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p)\n", |
133 | PFID(&md->body->fid1), inode); | |
da5ecb4d | 134 | } |
d7e09d03 | 135 | } |
0a3bdb00 | 136 | return inode; |
d7e09d03 PT |
137 | } |
138 | ||
139 | static void ll_invalidate_negative_children(struct inode *dir) | |
140 | { | |
141 | struct dentry *dentry, *tmp_subdir; | |
d7e09d03 | 142 | |
2bbec0ed | 143 | spin_lock(&dir->i_lock); |
9d5be52f | 144 | hlist_for_each_entry(dentry, &dir->i_dentry, d_u.d_alias) { |
d7e09d03 PT |
145 | spin_lock(&dentry->d_lock); |
146 | if (!list_empty(&dentry->d_subdirs)) { | |
147 | struct dentry *child; | |
148 | ||
149 | list_for_each_entry_safe(child, tmp_subdir, | |
150 | &dentry->d_subdirs, | |
946e51f2 | 151 | d_child) { |
2b0143b5 | 152 | if (d_really_is_negative(child)) |
b1d2a127 | 153 | d_lustre_invalidate(child, 1); |
d7e09d03 PT |
154 | } |
155 | } | |
156 | spin_unlock(&dentry->d_lock); | |
157 | } | |
2bbec0ed | 158 | spin_unlock(&dir->i_lock); |
d7e09d03 PT |
159 | } |
160 | ||
161 | int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc, | |
162 | void *data, int flag) | |
163 | { | |
d7e09d03 | 164 | struct lustre_handle lockh; |
45b2a010 | 165 | int rc; |
d7e09d03 PT |
166 | |
167 | switch (flag) { | |
168 | case LDLM_CB_BLOCKING: | |
169 | ldlm_lock2handle(lock, &lockh); | |
170 | rc = ldlm_cli_cancel(&lockh, LCF_ASYNC); | |
171 | if (rc < 0) { | |
45b2a010 | 172 | CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc); |
0a3bdb00 | 173 | return rc; |
d7e09d03 PT |
174 | } |
175 | break; | |
176 | case LDLM_CB_CANCELING: { | |
177 | struct inode *inode = ll_inode_from_resource_lock(lock); | |
d7e09d03 | 178 | __u64 bits = lock->l_policy_data.l_inodebits.bits; |
d7e09d03 PT |
179 | |
180 | /* Inode is set to lock->l_resource->lr_lvb_inode | |
c0894c6c OD |
181 | * for mdc - bug 24555 |
182 | */ | |
6e16818b | 183 | LASSERT(!lock->l_ast_data); |
d7e09d03 | 184 | |
6e16818b | 185 | if (!inode) |
d7e09d03 PT |
186 | break; |
187 | ||
45b2a010 | 188 | /* Invalidate all dentries associated with this inode */ |
5a9a80ba | 189 | LASSERT(ldlm_is_canceling(lock)); |
7fc1f831 | 190 | |
45b2a010 JH |
191 | if (!fid_res_name_eq(ll_inode2fid(inode), |
192 | &lock->l_resource->lr_name)) { | |
193 | LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)", | |
194 | PFID(ll_inode2fid(inode)), inode); | |
195 | LBUG(); | |
196 | } | |
197 | ||
198 | if (bits & MDS_INODELOCK_XATTR) { | |
7fc1f831 | 199 | ll_xattr_cache_destroy(inode); |
45b2a010 JH |
200 | bits &= ~MDS_INODELOCK_XATTR; |
201 | } | |
7fc1f831 | 202 | |
d7e09d03 | 203 | /* For OPEN locks we differentiate between lock modes |
c0894c6c OD |
204 | * LCK_CR, LCK_CW, LCK_PR - bug 22891 |
205 | */ | |
d7e09d03 | 206 | if (bits & MDS_INODELOCK_OPEN) |
45b2a010 | 207 | ll_have_md_lock(inode, &bits, lock->l_req_mode); |
d7e09d03 PT |
208 | |
209 | if (bits & MDS_INODELOCK_OPEN) { | |
45b2a010 JH |
210 | fmode_t fmode; |
211 | ||
d7e09d03 PT |
212 | switch (lock->l_req_mode) { |
213 | case LCK_CW: | |
45b2a010 | 214 | fmode = FMODE_WRITE; |
d7e09d03 PT |
215 | break; |
216 | case LCK_PR: | |
45b2a010 | 217 | fmode = FMODE_EXEC; |
d7e09d03 PT |
218 | break; |
219 | case LCK_CR: | |
45b2a010 | 220 | fmode = FMODE_READ; |
d7e09d03 PT |
221 | break; |
222 | default: | |
45b2a010 JH |
223 | LDLM_ERROR(lock, "bad lock mode for OPEN lock"); |
224 | LBUG(); | |
d7e09d03 | 225 | } |
45b2a010 JH |
226 | |
227 | ll_md_real_close(inode, fmode); | |
d7e09d03 PT |
228 | } |
229 | ||
45b2a010 JH |
230 | if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE | |
231 | MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM)) | |
232 | ll_have_md_lock(inode, &bits, LCK_MINMODE); | |
233 | ||
d7e09d03 | 234 | if (bits & MDS_INODELOCK_LAYOUT) { |
45b2a010 JH |
235 | struct cl_object_conf conf = { |
236 | .coc_opc = OBJECT_CONF_INVALIDATE, | |
237 | .coc_inode = inode, | |
238 | }; | |
d7e09d03 | 239 | |
d7e09d03 | 240 | rc = ll_layout_conf(inode, &conf); |
45b2a010 JH |
241 | if (rc < 0) |
242 | CDEBUG(D_INODE, "cannot invalidate layout of " | |
243 | DFID": rc = %d\n", | |
244 | PFID(ll_inode2fid(inode)), rc); | |
d7e09d03 PT |
245 | } |
246 | ||
ae5ef67b | 247 | if (bits & MDS_INODELOCK_UPDATE) { |
45b2a010 JH |
248 | struct ll_inode_info *lli = ll_i2info(inode); |
249 | ||
ae5ef67b | 250 | spin_lock(&lli->lli_lock); |
d7e09d03 | 251 | lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK; |
ae5ef67b SB |
252 | spin_unlock(&lli->lli_lock); |
253 | } | |
d7e09d03 | 254 | |
45b2a010 | 255 | if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) { |
97a075cd JN |
256 | CDEBUG(D_INODE, "invalidating inode "DFID"\n", |
257 | PFID(ll_inode2fid(inode))); | |
d7e09d03 PT |
258 | truncate_inode_pages(inode->i_mapping, 0); |
259 | ll_invalidate_negative_children(inode); | |
260 | } | |
261 | ||
45b2a010 | 262 | if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) && |
6e16818b | 263 | inode->i_sb->s_root && |
5242d422 | 264 | !is_root_inode(inode)) |
d7e09d03 | 265 | ll_invalidate_aliases(inode); |
45b2a010 | 266 | |
d7e09d03 PT |
267 | iput(inode); |
268 | break; | |
269 | } | |
270 | default: | |
271 | LBUG(); | |
272 | } | |
273 | ||
0a3bdb00 | 274 | return 0; |
d7e09d03 PT |
275 | } |
276 | ||
277 | __u32 ll_i2suppgid(struct inode *i) | |
278 | { | |
4b1a25f0 PT |
279 | if (in_group_p(i->i_gid)) |
280 | return (__u32)from_kgid(&init_user_ns, i->i_gid); | |
d7e09d03 PT |
281 | else |
282 | return (__u32)(-1); | |
283 | } | |
284 | ||
285 | /* Pack the required supplementary groups into the supplied groups array. | |
286 | * If we don't need to use the groups from the target inode(s) then we | |
287 | * instead pack one or more groups from the user's supplementary group | |
c0894c6c OD |
288 | * array in case it might be useful. Not needed if doing an MDS-side upcall. |
289 | */ | |
d7e09d03 PT |
290 | void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2) |
291 | { | |
6e16818b | 292 | LASSERT(i1); |
d7e09d03 PT |
293 | |
294 | suppgids[0] = ll_i2suppgid(i1); | |
295 | ||
296 | if (i2) | |
297 | suppgids[1] = ll_i2suppgid(i2); | |
298 | else | |
299 | suppgids[1] = -1; | |
d7e09d03 PT |
300 | } |
301 | ||
302 | /* | |
303 | * try to reuse three types of dentry: | |
304 | * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid | |
305 | * by concurrent .revalidate). | |
306 | * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may | |
307 | * be cleared by others calling d_lustre_revalidate). | |
308 | * 3. DISCONNECTED alias. | |
309 | */ | |
310 | static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry) | |
311 | { | |
312 | struct dentry *alias, *discon_alias, *invalid_alias; | |
d7e09d03 | 313 | |
9d5be52f | 314 | if (hlist_empty(&inode->i_dentry)) |
d7e09d03 PT |
315 | return NULL; |
316 | ||
7551b8b5 NC |
317 | discon_alias = NULL; |
318 | invalid_alias = NULL; | |
d7e09d03 | 319 | |
2bbec0ed | 320 | spin_lock(&inode->i_lock); |
9d5be52f | 321 | hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { |
d7e09d03 PT |
322 | LASSERT(alias != dentry); |
323 | ||
324 | spin_lock(&alias->d_lock); | |
325 | if (alias->d_flags & DCACHE_DISCONNECTED) | |
326 | /* LASSERT(last_discon == NULL); LU-405, bz 20055 */ | |
327 | discon_alias = alias; | |
328 | else if (alias->d_parent == dentry->d_parent && | |
329 | alias->d_name.hash == dentry->d_name.hash && | |
330 | alias->d_name.len == dentry->d_name.len && | |
331 | memcmp(alias->d_name.name, dentry->d_name.name, | |
332 | dentry->d_name.len) == 0) | |
333 | invalid_alias = alias; | |
334 | spin_unlock(&alias->d_lock); | |
335 | ||
336 | if (invalid_alias) | |
337 | break; | |
338 | } | |
339 | alias = invalid_alias ?: discon_alias ?: NULL; | |
340 | if (alias) { | |
341 | spin_lock(&alias->d_lock); | |
342 | dget_dlock(alias); | |
343 | spin_unlock(&alias->d_lock); | |
344 | } | |
2bbec0ed | 345 | spin_unlock(&inode->i_lock); |
d7e09d03 PT |
346 | |
347 | return alias; | |
348 | } | |
349 | ||
350 | /* | |
351 | * Similar to d_splice_alias(), but lustre treats invalid alias | |
352 | * similar to DCACHE_DISCONNECTED, and tries to use it anyway. | |
353 | */ | |
354 | struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de) | |
355 | { | |
356 | struct dentry *new; | |
3ea8f3bc | 357 | int rc; |
d7e09d03 PT |
358 | |
359 | if (inode) { | |
360 | new = ll_find_alias(inode, de); | |
361 | if (new) { | |
3ea8f3bc LS |
362 | rc = ll_d_init(new); |
363 | if (rc < 0) { | |
364 | dput(new); | |
365 | return ERR_PTR(rc); | |
366 | } | |
d7e09d03 PT |
367 | d_move(new, de); |
368 | iput(inode); | |
369 | CDEBUG(D_DENTRY, | |
370 | "Reuse dentry %p inode %p refc %d flags %#x\n", | |
2b0143b5 | 371 | new, d_inode(new), d_count(new), new->d_flags); |
d7e09d03 PT |
372 | return new; |
373 | } | |
374 | } | |
3ea8f3bc LS |
375 | rc = ll_d_init(de); |
376 | if (rc < 0) | |
377 | return ERR_PTR(rc); | |
d7e09d03 PT |
378 | d_add(de, inode); |
379 | CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n", | |
2b0143b5 | 380 | de, d_inode(de), d_count(de), de->d_flags); |
d7e09d03 PT |
381 | return de; |
382 | } | |
383 | ||
2d95f10e JH |
384 | static int ll_lookup_it_finish(struct ptlrpc_request *request, |
385 | struct lookup_intent *it, | |
386 | struct inode *parent, struct dentry **de) | |
d7e09d03 | 387 | { |
d7e09d03 PT |
388 | struct inode *inode = NULL; |
389 | __u64 bits = 0; | |
44ecac68 | 390 | int rc = 0; |
d7e09d03 PT |
391 | |
392 | /* NB 1 request reference will be taken away by ll_intent_lock() | |
c0894c6c OD |
393 | * when I return |
394 | */ | |
d7e09d03 | 395 | CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it, |
e476f2e5 | 396 | it->it_disposition); |
d7e09d03 PT |
397 | if (!it_disposition(it, DISP_LOOKUP_NEG)) { |
398 | rc = ll_prep_inode(&inode, request, (*de)->d_sb, it); | |
399 | if (rc) | |
0a3bdb00 | 400 | return rc; |
d7e09d03 PT |
401 | |
402 | ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits); | |
403 | ||
404 | /* We used to query real size from OSTs here, but actually | |
c0894c6c OD |
405 | * this is not needed. For stat() calls size would be updated |
406 | * from subsequent do_revalidate()->ll_inode_revalidate_it() in | |
407 | * 2.4 and | |
408 | * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6 | |
409 | * Everybody else who needs correct file size would call | |
410 | * ll_glimpse_size or some equivalent themselves anyway. | |
411 | * Also see bug 7198. | |
412 | */ | |
d7e09d03 PT |
413 | } |
414 | ||
415 | /* Only hash *de if it is unhashed (new dentry). | |
d0a0acc3 | 416 | * Atoimc_open may passing hashed dentries for open. |
d7e09d03 | 417 | */ |
3ea8f3bc | 418 | if (d_unhashed(*de)) { |
7486bc06 SP |
419 | struct dentry *alias; |
420 | ||
421 | alias = ll_splice_alias(inode, *de); | |
44ecac68 FY |
422 | if (IS_ERR(alias)) { |
423 | rc = PTR_ERR(alias); | |
424 | goto out; | |
425 | } | |
7486bc06 | 426 | *de = alias; |
08a78a27 | 427 | } else if (!it_disposition(it, DISP_LOOKUP_NEG) && |
428 | !it_disposition(it, DISP_OPEN_CREATE)) { | |
c0894c6c OD |
429 | /* With DISP_OPEN_CREATE dentry will be |
430 | * instantiated in ll_create_it. | |
431 | */ | |
6e16818b | 432 | LASSERT(!d_inode(*de)); |
08a78a27 | 433 | d_instantiate(*de, inode); |
3ea8f3bc | 434 | } |
d7e09d03 PT |
435 | |
436 | if (!it_disposition(it, DISP_LOOKUP_NEG)) { | |
437 | /* we have lookup look - unhide dentry */ | |
438 | if (bits & MDS_INODELOCK_LOOKUP) | |
439 | d_lustre_revalidate(*de); | |
440 | } else if (!it_disposition(it, DISP_OPEN_CREATE)) { | |
441 | /* If file created on server, don't depend on parent UPDATE | |
442 | * lock to unhide it. It is left hidden and next lookup can | |
443 | * find it in ll_splice_alias. | |
444 | */ | |
445 | /* Check that parent has UPDATE lock. */ | |
446 | struct lookup_intent parent_it = { | |
447 | .it_op = IT_GETATTR, | |
e476f2e5 | 448 | .it_lock_handle = 0 }; |
d7e09d03 PT |
449 | |
450 | if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, | |
451 | &ll_i2info(parent)->lli_fid, NULL)) { | |
452 | d_lustre_revalidate(*de); | |
453 | ll_intent_release(&parent_it); | |
454 | } | |
455 | } | |
456 | ||
44ecac68 FY |
457 | out: |
458 | if (rc != 0 && it->it_op & IT_OPEN) | |
459 | ll_open_cleanup((*de)->d_sb, request); | |
460 | ||
461 | return rc; | |
d7e09d03 PT |
462 | } |
463 | ||
464 | static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, | |
465 | struct lookup_intent *it, int lookup_flags) | |
466 | { | |
467 | struct lookup_intent lookup_it = { .it_op = IT_LOOKUP }; | |
468 | struct dentry *save = dentry, *retval; | |
469 | struct ptlrpc_request *req = NULL; | |
dbca51dd | 470 | struct inode *inode; |
d7e09d03 | 471 | struct md_op_data *op_data; |
d7e09d03 PT |
472 | __u32 opc; |
473 | int rc; | |
d7e09d03 PT |
474 | |
475 | if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen) | |
0a3bdb00 | 476 | return ERR_PTR(-ENAMETOOLONG); |
d7e09d03 | 477 | |
97a075cd JN |
478 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),intent=%s\n", |
479 | dentry, PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it)); | |
d7e09d03 PT |
480 | |
481 | if (d_mountpoint(dentry)) | |
482 | CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it)); | |
483 | ||
6e16818b | 484 | if (!it || it->it_op == IT_GETXATTR) |
2d95f10e | 485 | it = &lookup_it; |
d7e09d03 | 486 | |
d7e09d03 PT |
487 | if (it->it_op == IT_GETATTR) { |
488 | rc = ll_statahead_enter(parent, &dentry, 0); | |
489 | if (rc == 1) { | |
490 | if (dentry == save) | |
34e1f2bb JL |
491 | retval = NULL; |
492 | else | |
493 | retval = dentry; | |
494 | goto out; | |
d7e09d03 PT |
495 | } |
496 | } | |
497 | ||
1e8a576e | 498 | if (it->it_op & IT_CREAT) |
d7e09d03 PT |
499 | opc = LUSTRE_OPC_CREATE; |
500 | else | |
501 | opc = LUSTRE_OPC_ANY; | |
502 | ||
503 | op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name, | |
504 | dentry->d_name.len, lookup_flags, opc, | |
505 | NULL); | |
506 | if (IS_ERR(op_data)) | |
0a3bdb00 | 507 | return (void *)op_data; |
d7e09d03 PT |
508 | |
509 | /* enforce umask if acl disabled or MDS doesn't support umask */ | |
510 | if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent))) | |
511 | it->it_create_mode &= ~current_umask(); | |
512 | ||
513 | rc = md_intent_lock(ll_i2mdexp(parent), op_data, NULL, 0, it, | |
514 | lookup_flags, &req, ll_md_blocking_ast, 0); | |
515 | ll_finish_md_op_data(op_data); | |
34e1f2bb JL |
516 | if (rc < 0) { |
517 | retval = ERR_PTR(rc); | |
518 | goto out; | |
519 | } | |
d7e09d03 | 520 | |
2d95f10e | 521 | rc = ll_lookup_it_finish(req, it, parent, &dentry); |
d7e09d03 PT |
522 | if (rc != 0) { |
523 | ll_intent_release(it); | |
34e1f2bb JL |
524 | retval = ERR_PTR(rc); |
525 | goto out; | |
d7e09d03 PT |
526 | } |
527 | ||
2b0143b5 | 528 | inode = d_inode(dentry); |
dbca51dd AV |
529 | if ((it->it_op & IT_OPEN) && inode && |
530 | !S_ISREG(inode->i_mode) && | |
531 | !S_ISDIR(inode->i_mode)) { | |
532 | ll_release_openhandle(inode, it); | |
d7e09d03 | 533 | } |
dbca51dd | 534 | ll_lookup_finish_locks(it, inode); |
d7e09d03 PT |
535 | |
536 | if (dentry == save) | |
34e1f2bb | 537 | retval = NULL; |
d7e09d03 | 538 | else |
34e1f2bb | 539 | retval = dentry; |
d7e09d03 PT |
540 | out: |
541 | if (req) | |
542 | ptlrpc_req_finished(req); | |
6e16818b | 543 | if (it->it_op == IT_GETATTR && (!retval || retval == dentry)) |
d7e09d03 PT |
544 | ll_statahead_mark(parent, dentry); |
545 | return retval; | |
546 | } | |
547 | ||
548 | static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry, | |
549 | unsigned int flags) | |
550 | { | |
551 | struct lookup_intent *itp, it = { .it_op = IT_GETATTR }; | |
552 | struct dentry *de; | |
553 | ||
97a075cd JN |
554 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),flags=%u\n", |
555 | dentry, PFID(ll_inode2fid(parent)), parent, flags); | |
d7e09d03 PT |
556 | |
557 | /* Optimize away (CREATE && !OPEN). Let .create handle the race. */ | |
4f2fb455 | 558 | if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN)) |
d7e09d03 | 559 | return NULL; |
d7e09d03 PT |
560 | |
561 | if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE)) | |
562 | itp = NULL; | |
563 | else | |
564 | itp = ⁢ | |
565 | de = ll_lookup_it(parent, dentry, itp, 0); | |
566 | ||
6e16818b | 567 | if (itp) |
d7e09d03 PT |
568 | ll_intent_release(itp); |
569 | ||
570 | return de; | |
571 | } | |
572 | ||
573 | /* | |
574 | * For cached negative dentry and new dentry, handle lookup/create/open | |
575 | * together. | |
576 | */ | |
577 | static int ll_atomic_open(struct inode *dir, struct dentry *dentry, | |
578 | struct file *file, unsigned open_flags, | |
579 | umode_t mode, int *opened) | |
580 | { | |
581 | struct lookup_intent *it; | |
582 | struct dentry *de; | |
583 | long long lookup_flags = LOOKUP_OPEN; | |
584 | int rc = 0; | |
d7e09d03 | 585 | |
97a075cd JN |
586 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),file %p,open_flags %x,mode %x opened %d\n", |
587 | dentry, PFID(ll_inode2fid(dir)), dir, file, open_flags, mode, | |
588 | *opened); | |
d7e09d03 | 589 | |
496a51bd | 590 | it = kzalloc(sizeof(*it), GFP_NOFS); |
d7e09d03 | 591 | if (!it) |
0a3bdb00 | 592 | return -ENOMEM; |
d7e09d03 PT |
593 | |
594 | it->it_op = IT_OPEN; | |
1e8a576e | 595 | if (open_flags & O_CREAT) { |
d7e09d03 PT |
596 | it->it_op |= IT_CREAT; |
597 | lookup_flags |= LOOKUP_CREATE; | |
598 | } | |
599 | it->it_create_mode = (mode & S_IALLUGO) | S_IFREG; | |
600 | it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags); | |
601 | ||
602 | /* Dentry added to dcache tree in ll_lookup_it */ | |
603 | de = ll_lookup_it(dir, dentry, it, lookup_flags); | |
604 | if (IS_ERR(de)) | |
605 | rc = PTR_ERR(de); | |
6e16818b | 606 | else if (de) |
d7e09d03 PT |
607 | dentry = de; |
608 | ||
609 | if (!rc) { | |
610 | if (it_disposition(it, DISP_OPEN_CREATE)) { | |
611 | /* Dentry instantiated in ll_create_it. */ | |
612 | rc = ll_create_it(dir, dentry, mode, it); | |
613 | if (rc) { | |
614 | /* We dget in ll_splice_alias. */ | |
6e16818b | 615 | if (de) |
d7e09d03 PT |
616 | dput(de); |
617 | goto out_release; | |
618 | } | |
619 | ||
620 | *opened |= FILE_CREATED; | |
621 | } | |
2b0143b5 | 622 | if (d_really_is_positive(dentry) && it_disposition(it, DISP_OPEN_OPEN)) { |
d7e09d03 | 623 | /* Open dentry. */ |
2b0143b5 | 624 | if (S_ISFIFO(d_inode(dentry)->i_mode)) { |
411c9699 JH |
625 | /* We cannot call open here as it might |
626 | * deadlock. This case is unreachable in | |
627 | * practice because of OBD_CONNECT_NODEVOH. | |
d7e09d03 | 628 | */ |
d7e09d03 PT |
629 | rc = finish_no_open(file, de); |
630 | } else { | |
631 | file->private_data = it; | |
632 | rc = finish_open(file, dentry, NULL, opened); | |
633 | /* We dget in ll_splice_alias. finish_open takes | |
634 | * care of dget for fd open. | |
635 | */ | |
6e16818b | 636 | if (de) |
d7e09d03 PT |
637 | dput(de); |
638 | } | |
639 | } else { | |
640 | rc = finish_no_open(file, de); | |
641 | } | |
642 | } | |
643 | ||
644 | out_release: | |
645 | ll_intent_release(it); | |
97903a26 | 646 | kfree(it); |
d7e09d03 | 647 | |
0a3bdb00 | 648 | return rc; |
d7e09d03 PT |
649 | } |
650 | ||
d7e09d03 | 651 | /* We depend on "mode" being set with the proper file type/umask by now */ |
2d95f10e | 652 | static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it) |
d7e09d03 PT |
653 | { |
654 | struct inode *inode = NULL; | |
655 | struct ptlrpc_request *request = NULL; | |
656 | struct ll_sb_info *sbi = ll_i2sbi(dir); | |
657 | int rc; | |
d7e09d03 | 658 | |
e476f2e5 | 659 | LASSERT(it && it->it_disposition); |
d7e09d03 PT |
660 | |
661 | LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF)); | |
8bf86fd9 | 662 | request = it->it_request; |
d7e09d03 PT |
663 | it_clear_disposition(it, DISP_ENQ_CREATE_REF); |
664 | rc = ll_prep_inode(&inode, request, dir->i_sb, it); | |
34e1f2bb JL |
665 | if (rc) { |
666 | inode = ERR_PTR(rc); | |
667 | goto out; | |
668 | } | |
d7e09d03 | 669 | |
9d5be52f | 670 | LASSERT(hlist_empty(&inode->i_dentry)); |
d7e09d03 PT |
671 | |
672 | /* We asked for a lock on the directory, but were granted a | |
673 | * lock on the inode. Since we finally have an inode pointer, | |
c0894c6c OD |
674 | * stuff it in the lock. |
675 | */ | |
97a075cd JN |
676 | CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n", |
677 | PFID(ll_inode2fid(dir)), inode); | |
d7e09d03 | 678 | ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL); |
d7e09d03 PT |
679 | out: |
680 | ptlrpc_req_finished(request); | |
681 | return inode; | |
682 | } | |
683 | ||
684 | /* | |
685 | * By the time this is called, we already have created the directory cache | |
686 | * entry for the new file, but it is so far negative - it has no inode. | |
687 | * | |
688 | * We defer creating the OBD object(s) until open, to keep the intent and | |
689 | * non-intent code paths similar, and also because we do not have the MDS | |
690 | * inode number before calling ll_create_node() (which is needed for LOV), | |
691 | * so we would need to do yet another RPC to the MDS to store the LOV EA | |
692 | * data on the MDS. If needed, we would pass the PACKED lmm as data and | |
693 | * lmm_size in datalen (the MDS still has code which will handle that). | |
694 | * | |
695 | * If the create succeeds, we fill in the inode information | |
696 | * with d_instantiate(). | |
697 | */ | |
698 | static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode, | |
699 | struct lookup_intent *it) | |
700 | { | |
701 | struct inode *inode; | |
702 | int rc = 0; | |
d7e09d03 | 703 | |
97a075cd JN |
704 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), intent=%s\n", |
705 | dentry, PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it)); | |
d7e09d03 PT |
706 | |
707 | rc = it_open_error(DISP_OPEN_CREATE, it); | |
708 | if (rc) | |
0a3bdb00 | 709 | return rc; |
d7e09d03 | 710 | |
2d95f10e | 711 | inode = ll_create_node(dir, it); |
d7e09d03 | 712 | if (IS_ERR(inode)) |
0a3bdb00 | 713 | return PTR_ERR(inode); |
d7e09d03 | 714 | |
d7e09d03 | 715 | d_instantiate(dentry, inode); |
0a3bdb00 | 716 | return 0; |
d7e09d03 PT |
717 | } |
718 | ||
719 | static void ll_update_times(struct ptlrpc_request *request, | |
720 | struct inode *inode) | |
721 | { | |
722 | struct mdt_body *body = req_capsule_server_get(&request->rq_pill, | |
723 | &RMF_MDT_BODY); | |
724 | ||
725 | LASSERT(body); | |
726 | if (body->valid & OBD_MD_FLMTIME && | |
727 | body->mtime > LTIME_S(inode->i_mtime)) { | |
97a075cd JN |
728 | CDEBUG(D_INODE, "setting fid "DFID" mtime from %lu to %llu\n", |
729 | PFID(ll_inode2fid(inode)), LTIME_S(inode->i_mtime), | |
730 | body->mtime); | |
d7e09d03 PT |
731 | LTIME_S(inode->i_mtime) = body->mtime; |
732 | } | |
733 | if (body->valid & OBD_MD_FLCTIME && | |
734 | body->ctime > LTIME_S(inode->i_ctime)) | |
735 | LTIME_S(inode->i_ctime) = body->ctime; | |
736 | } | |
737 | ||
b2037bb6 | 738 | static int ll_new_node(struct inode *dir, struct dentry *dentry, |
d7e09d03 | 739 | const char *tgt, int mode, int rdev, |
b2037bb6 | 740 | __u32 opc) |
d7e09d03 PT |
741 | { |
742 | struct ptlrpc_request *request = NULL; | |
743 | struct md_op_data *op_data; | |
744 | struct inode *inode = NULL; | |
745 | struct ll_sb_info *sbi = ll_i2sbi(dir); | |
746 | int tgt_len = 0; | |
747 | int err; | |
748 | ||
6e16818b | 749 | if (unlikely(tgt)) |
d7e09d03 PT |
750 | tgt_len = strlen(tgt) + 1; |
751 | ||
b2037bb6 AV |
752 | op_data = ll_prep_md_op_data(NULL, dir, NULL, |
753 | dentry->d_name.name, | |
754 | dentry->d_name.len, | |
755 | 0, opc, NULL); | |
34e1f2bb JL |
756 | if (IS_ERR(op_data)) { |
757 | err = PTR_ERR(op_data); | |
758 | goto err_exit; | |
759 | } | |
d7e09d03 PT |
760 | |
761 | err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode, | |
4b1a25f0 PT |
762 | from_kuid(&init_user_ns, current_fsuid()), |
763 | from_kgid(&init_user_ns, current_fsgid()), | |
d7e09d03 PT |
764 | cfs_curproc_cap_pack(), rdev, &request); |
765 | ll_finish_md_op_data(op_data); | |
766 | if (err) | |
34e1f2bb | 767 | goto err_exit; |
d7e09d03 PT |
768 | |
769 | ll_update_times(request, dir); | |
770 | ||
b2037bb6 AV |
771 | err = ll_prep_inode(&inode, request, dir->i_sb, NULL); |
772 | if (err) | |
773 | goto err_exit; | |
d7e09d03 | 774 | |
b2037bb6 | 775 | d_instantiate(dentry, inode); |
d7e09d03 PT |
776 | err_exit: |
777 | ptlrpc_req_finished(request); | |
778 | ||
779 | return err; | |
780 | } | |
781 | ||
d6689e5f AV |
782 | static int ll_mknod(struct inode *dir, struct dentry *dchild, |
783 | umode_t mode, dev_t rdev) | |
d7e09d03 PT |
784 | { |
785 | int err; | |
d7e09d03 | 786 | |
97a075cd JN |
787 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p) mode %o dev %x\n", |
788 | dchild, PFID(ll_inode2fid(dir)), dir, mode, | |
789 | old_encode_dev(rdev)); | |
d7e09d03 PT |
790 | |
791 | if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir))) | |
792 | mode &= ~current_umask(); | |
793 | ||
794 | switch (mode & S_IFMT) { | |
795 | case 0: | |
796 | mode |= S_IFREG; /* for mode = 0 case, fallthrough */ | |
797 | case S_IFREG: | |
798 | case S_IFCHR: | |
799 | case S_IFBLK: | |
800 | case S_IFIFO: | |
801 | case S_IFSOCK: | |
b2037bb6 AV |
802 | err = ll_new_node(dir, dchild, NULL, mode, |
803 | old_encode_dev(rdev), | |
d7e09d03 PT |
804 | LUSTRE_OPC_MKNOD); |
805 | break; | |
806 | case S_IFDIR: | |
807 | err = -EPERM; | |
808 | break; | |
809 | default: | |
810 | err = -EINVAL; | |
811 | } | |
812 | ||
813 | if (!err) | |
814 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1); | |
815 | ||
0a3bdb00 | 816 | return err; |
d7e09d03 PT |
817 | } |
818 | ||
819 | /* | |
820 | * Plain create. Intent create is handled in atomic_open. | |
821 | */ | |
822 | static int ll_create_nd(struct inode *dir, struct dentry *dentry, | |
823 | umode_t mode, bool want_excl) | |
824 | { | |
825 | int rc; | |
826 | ||
97a075cd JN |
827 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), flags=%u, excl=%d\n", |
828 | dentry, PFID(ll_inode2fid(dir)), dir, mode, want_excl); | |
d7e09d03 | 829 | |
d6689e5f | 830 | rc = ll_mknod(dir, dentry, mode, 0); |
d7e09d03 PT |
831 | |
832 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1); | |
833 | ||
09561a53 AV |
834 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n", |
835 | dentry, d_unhashed(dentry)); | |
d7e09d03 PT |
836 | |
837 | return rc; | |
838 | } | |
839 | ||
d7e09d03 PT |
840 | int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir) |
841 | { | |
842 | struct mdt_body *body; | |
843 | struct lov_mds_md *eadata; | |
844 | struct lov_stripe_md *lsm = NULL; | |
845 | struct obd_trans_info oti = { 0 }; | |
846 | struct obdo *oa; | |
d7e09d03 | 847 | int rc; |
d7e09d03 PT |
848 | |
849 | /* req is swabbed so this is safe */ | |
850 | body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY); | |
851 | if (!(body->valid & OBD_MD_FLEASIZE)) | |
0a3bdb00 | 852 | return 0; |
d7e09d03 PT |
853 | |
854 | if (body->eadatasize == 0) { | |
855 | CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n"); | |
34e1f2bb JL |
856 | rc = -EPROTO; |
857 | goto out; | |
d7e09d03 PT |
858 | } |
859 | ||
860 | /* The MDS sent back the EA because we unlinked the last reference | |
861 | * to this file. Use this EA to unlink the objects on the OST. | |
862 | * It's opaque so we don't swab here; we leave it to obd_unpackmd() to | |
c0894c6c OD |
863 | * check it is complete and sensible. |
864 | */ | |
d7e09d03 PT |
865 | eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD, |
866 | body->eadatasize); | |
6e16818b | 867 | LASSERT(eadata); |
d7e09d03 PT |
868 | |
869 | rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->eadatasize); | |
870 | if (rc < 0) { | |
871 | CERROR("obd_unpackmd: %d\n", rc); | |
34e1f2bb | 872 | goto out; |
d7e09d03 PT |
873 | } |
874 | LASSERT(rc >= sizeof(*lsm)); | |
875 | ||
21068c46 | 876 | oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS); |
6e16818b | 877 | if (!oa) { |
34e1f2bb JL |
878 | rc = -ENOMEM; |
879 | goto out_free_memmd; | |
880 | } | |
d7e09d03 PT |
881 | |
882 | oa->o_oi = lsm->lsm_oi; | |
883 | oa->o_mode = body->mode & S_IFMT; | |
884 | oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP; | |
885 | ||
886 | if (body->valid & OBD_MD_FLCOOKIE) { | |
887 | oa->o_valid |= OBD_MD_FLCOOKIE; | |
888 | oti.oti_logcookies = | |
889 | req_capsule_server_sized_get(&request->rq_pill, | |
890 | &RMF_LOGCOOKIES, | |
891 | sizeof(struct llog_cookie) * | |
892 | lsm->lsm_stripe_count); | |
6e16818b | 893 | if (!oti.oti_logcookies) { |
d7e09d03 PT |
894 | oa->o_valid &= ~OBD_MD_FLCOOKIE; |
895 | body->valid &= ~OBD_MD_FLCOOKIE; | |
896 | } | |
897 | } | |
898 | ||
d7e09d03 | 899 | rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti, |
ef2e0f55 | 900 | ll_i2mdexp(dir)); |
d7e09d03 PT |
901 | if (rc) |
902 | CERROR("obd destroy objid "DOSTID" error %d\n", | |
903 | POSTID(&lsm->lsm_oi), rc); | |
904 | out_free_memmd: | |
905 | obd_free_memmd(ll_i2dtexp(dir), &lsm); | |
2ba262fb | 906 | kmem_cache_free(obdo_cachep, oa); |
d7e09d03 PT |
907 | out: |
908 | return rc; | |
909 | } | |
910 | ||
521f2ad7 AV |
911 | /* ll_unlink() doesn't update the inode with the new link count. |
912 | * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there | |
913 | * is any lock existing. They will recycle dentries and inodes based upon locks | |
c0894c6c OD |
914 | * too. b=20433 |
915 | */ | |
96d61c24 | 916 | static int ll_unlink(struct inode *dir, struct dentry *dchild) |
d7e09d03 | 917 | { |
521f2ad7 AV |
918 | struct ptlrpc_request *request = NULL; |
919 | struct md_op_data *op_data; | |
920 | int rc; | |
43550121 | 921 | |
521f2ad7 | 922 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n", |
96d61c24 | 923 | dchild, dir->i_ino, dir->i_generation, dir); |
521f2ad7 | 924 | |
521f2ad7 | 925 | op_data = ll_prep_md_op_data(NULL, dir, NULL, |
96d61c24 AP |
926 | dchild->d_name.name, |
927 | dchild->d_name.len, | |
521f2ad7 AV |
928 | 0, LUSTRE_OPC_ANY, NULL); |
929 | if (IS_ERR(op_data)) | |
930 | return PTR_ERR(op_data); | |
931 | ||
3c4b9d09 AP |
932 | if (dchild && dchild->d_inode) |
933 | op_data->op_fid3 = *ll_inode2fid(dchild->d_inode); | |
934 | ||
521f2ad7 AV |
935 | op_data->op_fid2 = op_data->op_fid3; |
936 | rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request); | |
937 | ll_finish_md_op_data(op_data); | |
938 | if (rc) | |
939 | goto out; | |
940 | ||
941 | ll_update_times(request, dir); | |
942 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1); | |
943 | ||
944 | rc = ll_objects_destroy(request, dir); | |
945 | out: | |
946 | ptlrpc_req_finished(request); | |
947 | return rc; | |
d7e09d03 PT |
948 | } |
949 | ||
e3befdc7 | 950 | static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
d7e09d03 | 951 | { |
7c2f9094 AV |
952 | int err; |
953 | ||
97a075cd JN |
954 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir"DFID"(%p)\n", |
955 | dentry, PFID(ll_inode2fid(dir)), dir); | |
7c2f9094 AV |
956 | |
957 | if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir))) | |
958 | mode &= ~current_umask(); | |
959 | mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR; | |
b2037bb6 | 960 | err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR); |
7c2f9094 AV |
961 | |
962 | if (!err) | |
963 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1); | |
964 | ||
965 | return err; | |
d7e09d03 PT |
966 | } |
967 | ||
96d61c24 | 968 | static int ll_rmdir(struct inode *dir, struct dentry *dchild) |
d7e09d03 | 969 | { |
55dec617 AV |
970 | struct ptlrpc_request *request = NULL; |
971 | struct md_op_data *op_data; | |
972 | int rc; | |
973 | ||
97a075cd JN |
974 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n", |
975 | dchild, PFID(ll_inode2fid(dir)), dir); | |
55dec617 | 976 | |
55dec617 | 977 | op_data = ll_prep_md_op_data(NULL, dir, NULL, |
96d61c24 AP |
978 | dchild->d_name.name, |
979 | dchild->d_name.len, | |
55dec617 AV |
980 | S_IFDIR, LUSTRE_OPC_ANY, NULL); |
981 | if (IS_ERR(op_data)) | |
982 | return PTR_ERR(op_data); | |
983 | ||
3c4b9d09 AP |
984 | if (dchild && dchild->d_inode) |
985 | op_data->op_fid3 = *ll_inode2fid(dchild->d_inode); | |
986 | ||
55dec617 AV |
987 | op_data->op_fid2 = op_data->op_fid3; |
988 | rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request); | |
989 | ll_finish_md_op_data(op_data); | |
990 | if (rc == 0) { | |
991 | ll_update_times(request, dir); | |
992 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1); | |
993 | } | |
994 | ||
995 | ptlrpc_req_finished(request); | |
996 | return rc; | |
d7e09d03 PT |
997 | } |
998 | ||
999 | static int ll_symlink(struct inode *dir, struct dentry *dentry, | |
1000 | const char *oldname) | |
1001 | { | |
60dd654e AV |
1002 | int err; |
1003 | ||
97a075cd JN |
1004 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),target=%.*s\n", |
1005 | dentry, PFID(ll_inode2fid(dir)), dir, 3000, oldname); | |
60dd654e | 1006 | |
b2037bb6 | 1007 | err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO, |
e15ba45d | 1008 | 0, LUSTRE_OPC_SYMLINK); |
60dd654e AV |
1009 | |
1010 | if (!err) | |
1011 | ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1); | |
1012 | ||
1013 | return err; | |
d7e09d03 PT |
1014 | } |
1015 | ||
1016 | static int ll_link(struct dentry *old_dentry, struct inode *dir, | |
1017 | struct dentry *new_dentry) | |
1018 | { | |
2b0143b5 | 1019 | struct inode *src = d_inode(old_dentry); |
59cc93ef AV |
1020 | struct ll_sb_info *sbi = ll_i2sbi(dir); |
1021 | struct ptlrpc_request *request = NULL; | |
1022 | struct md_op_data *op_data; | |
1023 | int err; | |
1024 | ||
97a075cd JN |
1025 | CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), target=%pd\n", |
1026 | PFID(ll_inode2fid(src)), src, PFID(ll_inode2fid(dir)), dir, | |
1027 | new_dentry); | |
59cc93ef AV |
1028 | |
1029 | op_data = ll_prep_md_op_data(NULL, src, dir, new_dentry->d_name.name, | |
1030 | new_dentry->d_name.len, | |
1031 | 0, LUSTRE_OPC_ANY, NULL); | |
1032 | if (IS_ERR(op_data)) | |
1033 | return PTR_ERR(op_data); | |
1034 | ||
1035 | err = md_link(sbi->ll_md_exp, op_data, &request); | |
1036 | ll_finish_md_op_data(op_data); | |
1037 | if (err) | |
1038 | goto out; | |
1039 | ||
1040 | ll_update_times(request, dir); | |
1041 | ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1); | |
1042 | out: | |
1043 | ptlrpc_req_finished(request); | |
1044 | return err; | |
d7e09d03 PT |
1045 | } |
1046 | ||
96d61c24 AP |
1047 | static int ll_rename(struct inode *src, struct dentry *src_dchild, |
1048 | struct inode *tgt, struct dentry *tgt_dchild) | |
d7e09d03 | 1049 | { |
78851093 | 1050 | struct ptlrpc_request *request = NULL; |
96d61c24 | 1051 | struct ll_sb_info *sbi = ll_i2sbi(src); |
78851093 | 1052 | struct md_op_data *op_data; |
d7e09d03 | 1053 | int err; |
78851093 AV |
1054 | |
1055 | CDEBUG(D_VFSTRACE, | |
97a075cd JN |
1056 | "VFS Op:oldname=%pd, src_dir="DFID"(%p), newname=%pd, tgt_dir="DFID"(%p)\n", |
1057 | src_dchild, PFID(ll_inode2fid(src)), src, | |
1058 | tgt_dchild, PFID(ll_inode2fid(tgt)), tgt); | |
78851093 | 1059 | |
96d61c24 | 1060 | op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0, |
78851093 AV |
1061 | LUSTRE_OPC_ANY, NULL); |
1062 | if (IS_ERR(op_data)) | |
1063 | return PTR_ERR(op_data); | |
1064 | ||
3c4b9d09 AP |
1065 | if (src_dchild && src_dchild->d_inode) |
1066 | op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode); | |
1067 | if (tgt_dchild && tgt_dchild->d_inode) | |
1068 | op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode); | |
1069 | ||
78851093 | 1070 | err = md_rename(sbi->ll_md_exp, op_data, |
96d61c24 AP |
1071 | src_dchild->d_name.name, |
1072 | src_dchild->d_name.len, | |
1073 | tgt_dchild->d_name.name, | |
1074 | tgt_dchild->d_name.len, &request); | |
78851093 | 1075 | ll_finish_md_op_data(op_data); |
d7e09d03 | 1076 | if (!err) { |
96d61c24 AP |
1077 | ll_update_times(request, src); |
1078 | ll_update_times(request, tgt); | |
78851093 | 1079 | ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1); |
96d61c24 | 1080 | err = ll_objects_destroy(request, src); |
d7e09d03 | 1081 | } |
78851093 AV |
1082 | |
1083 | ptlrpc_req_finished(request); | |
1084 | if (!err) | |
96d61c24 | 1085 | d_move(src_dchild, tgt_dchild); |
d7e09d03 PT |
1086 | return err; |
1087 | } | |
1088 | ||
2d95f10e | 1089 | const struct inode_operations ll_dir_inode_operations = { |
d7e09d03 PT |
1090 | .mknod = ll_mknod, |
1091 | .atomic_open = ll_atomic_open, | |
1092 | .lookup = ll_lookup_nd, | |
1093 | .create = ll_create_nd, | |
1094 | /* We need all these non-raw things for NFSD, to not patch it. */ | |
1095 | .unlink = ll_unlink, | |
1096 | .mkdir = ll_mkdir, | |
1097 | .rmdir = ll_rmdir, | |
1098 | .symlink = ll_symlink, | |
1099 | .link = ll_link, | |
1100 | .rename = ll_rename, | |
1101 | .setattr = ll_setattr, | |
1102 | .getattr = ll_getattr, | |
1103 | .permission = ll_inode_permission, | |
1104 | .setxattr = ll_setxattr, | |
1105 | .getxattr = ll_getxattr, | |
1106 | .listxattr = ll_listxattr, | |
1107 | .removexattr = ll_removexattr, | |
1108 | .get_acl = ll_get_acl, | |
1109 | }; | |
1110 | ||
2d95f10e | 1111 | const struct inode_operations ll_special_inode_operations = { |
d7e09d03 PT |
1112 | .setattr = ll_setattr, |
1113 | .getattr = ll_getattr, | |
1114 | .permission = ll_inode_permission, | |
1115 | .setxattr = ll_setxattr, | |
1116 | .getxattr = ll_getxattr, | |
1117 | .listxattr = ll_listxattr, | |
1118 | .removexattr = ll_removexattr, | |
1119 | .get_acl = ll_get_acl, | |
1120 | }; |