diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2012-06-05 09:10:27 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-07-14 08:33:18 -0400 |
commit | 015c3bbcd88df2305aae5b017a9c91c08b380aa1 (patch) | |
tree | 25f5e936ad16eddda39477a64addb4b54970bbd2 /fs/namei.c | |
parent | e43ae79c540270865918dab5ac914c74f43101e2 (diff) |
vfs: remove open intents from nameidata
All users of open intents have been converted to use ->atomic_{open,create}.
This patch gets rid of nd->intent.open and related infrastructure.
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/fs/namei.c b/fs/namei.c index 9e11ae83bff6..0ed876259f8b 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -463,22 +463,6 @@ err_root: | |||
463 | return -ECHILD; | 463 | return -ECHILD; |
464 | } | 464 | } |
465 | 465 | ||
466 | /** | ||
467 | * release_open_intent - free up open intent resources | ||
468 | * @nd: pointer to nameidata | ||
469 | */ | ||
470 | void release_open_intent(struct nameidata *nd) | ||
471 | { | ||
472 | struct file *file = nd->intent.open.file; | ||
473 | |||
474 | if (file && !IS_ERR(file)) { | ||
475 | if (file->f_path.dentry == NULL) | ||
476 | put_filp(file); | ||
477 | else | ||
478 | fput(file); | ||
479 | } | ||
480 | } | ||
481 | |||
482 | static inline int d_revalidate(struct dentry *dentry, struct nameidata *nd) | 466 | static inline int d_revalidate(struct dentry *dentry, struct nameidata *nd) |
483 | { | 467 | { |
484 | return dentry->d_op->d_revalidate(dentry, nd); | 468 | return dentry->d_op->d_revalidate(dentry, nd); |
@@ -2210,7 +2194,8 @@ static int may_o_create(struct path *dir, struct dentry *dentry, umode_t mode) | |||
2210 | } | 2194 | } |
2211 | 2195 | ||
2212 | static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, | 2196 | static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, |
2213 | struct path *path, const struct open_flags *op, | 2197 | struct path *path, struct opendata *od, |
2198 | const struct open_flags *op, | ||
2214 | int *want_write, bool need_lookup, | 2199 | int *want_write, bool need_lookup, |
2215 | bool *created) | 2200 | bool *created) |
2216 | { | 2201 | { |
@@ -2219,7 +2204,6 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2219 | umode_t mode; | 2204 | umode_t mode; |
2220 | int error; | 2205 | int error; |
2221 | int acc_mode; | 2206 | int acc_mode; |
2222 | struct opendata od; | ||
2223 | struct file *filp; | 2207 | struct file *filp; |
2224 | int create_error = 0; | 2208 | int create_error = 0; |
2225 | struct dentry *const DENTRY_NOT_SET = (void *) -1UL; | 2209 | struct dentry *const DENTRY_NOT_SET = (void *) -1UL; |
@@ -2285,14 +2269,13 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2285 | if (nd->flags & LOOKUP_DIRECTORY) | 2269 | if (nd->flags & LOOKUP_DIRECTORY) |
2286 | open_flag |= O_DIRECTORY; | 2270 | open_flag |= O_DIRECTORY; |
2287 | 2271 | ||
2288 | od.dentry = DENTRY_NOT_SET; | 2272 | od->dentry = DENTRY_NOT_SET; |
2289 | od.mnt = nd->path.mnt; | 2273 | od->mnt = nd->path.mnt; |
2290 | od.filp = &nd->intent.open.file; | 2274 | filp = dir->i_op->atomic_open(dir, dentry, od, open_flag, mode, |
2291 | filp = dir->i_op->atomic_open(dir, dentry, &od, open_flag, mode, | ||
2292 | created); | 2275 | created); |
2293 | if (IS_ERR(filp)) { | 2276 | if (IS_ERR(filp)) { |
2294 | if (WARN_ON(od.dentry != DENTRY_NOT_SET)) | 2277 | if (WARN_ON(od->dentry != DENTRY_NOT_SET)) |
2295 | dput(od.dentry); | 2278 | dput(od->dentry); |
2296 | 2279 | ||
2297 | if (create_error && PTR_ERR(filp) == -ENOENT) | 2280 | if (create_error && PTR_ERR(filp) == -ENOENT) |
2298 | filp = ERR_PTR(create_error); | 2281 | filp = ERR_PTR(create_error); |
@@ -2306,13 +2289,13 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2306 | } | 2289 | } |
2307 | 2290 | ||
2308 | if (!filp) { | 2291 | if (!filp) { |
2309 | if (WARN_ON(od.dentry == DENTRY_NOT_SET)) { | 2292 | if (WARN_ON(od->dentry == DENTRY_NOT_SET)) { |
2310 | filp = ERR_PTR(-EIO); | 2293 | filp = ERR_PTR(-EIO); |
2311 | goto out; | 2294 | goto out; |
2312 | } | 2295 | } |
2313 | if (od.dentry) { | 2296 | if (od->dentry) { |
2314 | dput(dentry); | 2297 | dput(dentry); |
2315 | dentry = od.dentry; | 2298 | dentry = od->dentry; |
2316 | } | 2299 | } |
2317 | goto looked_up; | 2300 | goto looked_up; |
2318 | } | 2301 | } |
@@ -2375,6 +2358,7 @@ looked_up: | |||
2375 | * was performed, only lookup. | 2358 | * was performed, only lookup. |
2376 | */ | 2359 | */ |
2377 | static struct file *lookup_open(struct nameidata *nd, struct path *path, | 2360 | static struct file *lookup_open(struct nameidata *nd, struct path *path, |
2361 | struct opendata *od, | ||
2378 | const struct open_flags *op, | 2362 | const struct open_flags *op, |
2379 | int *want_write, bool *created) | 2363 | int *want_write, bool *created) |
2380 | { | 2364 | { |
@@ -2394,7 +2378,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, | |||
2394 | goto out_no_open; | 2378 | goto out_no_open; |
2395 | 2379 | ||
2396 | if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) { | 2380 | if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) { |
2397 | return atomic_open(nd, dentry, path, op, want_write, | 2381 | return atomic_open(nd, dentry, path, od, op, want_write, |
2398 | need_lookup, created); | 2382 | need_lookup, created); |
2399 | } | 2383 | } |
2400 | 2384 | ||
@@ -2416,7 +2400,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, | |||
2416 | * rw->ro transition does not occur between | 2400 | * rw->ro transition does not occur between |
2417 | * the time when the file is created and when | 2401 | * the time when the file is created and when |
2418 | * a permanent write count is taken through | 2402 | * a permanent write count is taken through |
2419 | * the 'struct file' in nameidata_to_filp(). | 2403 | * the 'struct file' in finish_open(). |
2420 | */ | 2404 | */ |
2421 | error = mnt_want_write(nd->path.mnt); | 2405 | error = mnt_want_write(nd->path.mnt); |
2422 | if (error) | 2406 | if (error) |
@@ -2444,7 +2428,8 @@ out_dput: | |||
2444 | * Handle the last step of open() | 2428 | * Handle the last step of open() |
2445 | */ | 2429 | */ |
2446 | static struct file *do_last(struct nameidata *nd, struct path *path, | 2430 | static struct file *do_last(struct nameidata *nd, struct path *path, |
2447 | const struct open_flags *op, const char *pathname) | 2431 | struct opendata *od, const struct open_flags *op, |
2432 | const char *pathname) | ||
2448 | { | 2433 | { |
2449 | struct dentry *dir = nd->path.dentry; | 2434 | struct dentry *dir = nd->path.dentry; |
2450 | int open_flag = op->open_flag; | 2435 | int open_flag = op->open_flag; |
@@ -2521,7 +2506,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, | |||
2521 | 2506 | ||
2522 | retry_lookup: | 2507 | retry_lookup: |
2523 | mutex_lock(&dir->d_inode->i_mutex); | 2508 | mutex_lock(&dir->d_inode->i_mutex); |
2524 | filp = lookup_open(nd, path, op, &want_write, &created); | 2509 | filp = lookup_open(nd, path, od, op, &want_write, &created); |
2525 | mutex_unlock(&dir->d_inode->i_mutex); | 2510 | mutex_unlock(&dir->d_inode->i_mutex); |
2526 | 2511 | ||
2527 | if (filp) { | 2512 | if (filp) { |
@@ -2627,7 +2612,8 @@ common: | |||
2627 | error = may_open(&nd->path, acc_mode, open_flag); | 2612 | error = may_open(&nd->path, acc_mode, open_flag); |
2628 | if (error) | 2613 | if (error) |
2629 | goto exit; | 2614 | goto exit; |
2630 | filp = nameidata_to_filp(nd); | 2615 | od->mnt = nd->path.mnt; |
2616 | filp = finish_open(od, nd->path.dentry, NULL); | ||
2631 | if (filp == ERR_PTR(-EOPENSTALE) && save_parent.dentry && !retried) { | 2617 | if (filp == ERR_PTR(-EOPENSTALE) && save_parent.dentry && !retried) { |
2632 | BUG_ON(save_parent.dentry != dir); | 2618 | BUG_ON(save_parent.dentry != dir); |
2633 | path_put(&nd->path); | 2619 | path_put(&nd->path); |
@@ -2642,6 +2628,11 @@ common: | |||
2642 | retried = true; | 2628 | retried = true; |
2643 | goto retry_lookup; | 2629 | goto retry_lookup; |
2644 | } | 2630 | } |
2631 | if (IS_ERR(filp)) | ||
2632 | goto out; | ||
2633 | error = open_check_o_direct(filp); | ||
2634 | if (error) | ||
2635 | goto exit_fput; | ||
2645 | opened: | 2636 | opened: |
2646 | if (!IS_ERR(filp)) { | 2637 | if (!IS_ERR(filp)) { |
2647 | error = ima_file_check(filp, op->acc_mode); | 2638 | error = ima_file_check(filp, op->acc_mode); |
@@ -2671,24 +2662,26 @@ exit_dput: | |||
2671 | exit: | 2662 | exit: |
2672 | filp = ERR_PTR(error); | 2663 | filp = ERR_PTR(error); |
2673 | goto out; | 2664 | goto out; |
2665 | exit_fput: | ||
2666 | fput(filp); | ||
2667 | goto exit; | ||
2668 | |||
2674 | } | 2669 | } |
2675 | 2670 | ||
2676 | static struct file *path_openat(int dfd, const char *pathname, | 2671 | static struct file *path_openat(int dfd, const char *pathname, |
2677 | struct nameidata *nd, const struct open_flags *op, int flags) | 2672 | struct nameidata *nd, const struct open_flags *op, int flags) |
2678 | { | 2673 | { |
2679 | struct file *base = NULL; | 2674 | struct file *base = NULL; |
2680 | struct file *filp; | 2675 | struct opendata od; |
2676 | struct file *res; | ||
2681 | struct path path; | 2677 | struct path path; |
2682 | int error; | 2678 | int error; |
2683 | 2679 | ||
2684 | filp = get_empty_filp(); | 2680 | od.filp = get_empty_filp(); |
2685 | if (!filp) | 2681 | if (!od.filp) |
2686 | return ERR_PTR(-ENFILE); | 2682 | return ERR_PTR(-ENFILE); |
2687 | 2683 | ||
2688 | filp->f_flags = op->open_flag; | 2684 | od.filp->f_flags = op->open_flag; |
2689 | nd->intent.open.file = filp; | ||
2690 | nd->intent.open.flags = open_to_namei_flags(op->open_flag); | ||
2691 | nd->intent.open.create_mode = op->mode; | ||
2692 | 2685 | ||
2693 | error = path_init(dfd, pathname, flags | LOOKUP_PARENT, nd, &base); | 2686 | error = path_init(dfd, pathname, flags | LOOKUP_PARENT, nd, &base); |
2694 | if (unlikely(error)) | 2687 | if (unlikely(error)) |
@@ -2699,14 +2692,14 @@ static struct file *path_openat(int dfd, const char *pathname, | |||
2699 | if (unlikely(error)) | 2692 | if (unlikely(error)) |
2700 | goto out_filp; | 2693 | goto out_filp; |
2701 | 2694 | ||
2702 | filp = do_last(nd, &path, op, pathname); | 2695 | res = do_last(nd, &path, &od, op, pathname); |
2703 | while (unlikely(!filp)) { /* trailing symlink */ | 2696 | while (unlikely(!res)) { /* trailing symlink */ |
2704 | struct path link = path; | 2697 | struct path link = path; |
2705 | void *cookie; | 2698 | void *cookie; |
2706 | if (!(nd->flags & LOOKUP_FOLLOW)) { | 2699 | if (!(nd->flags & LOOKUP_FOLLOW)) { |
2707 | path_put_conditional(&path, nd); | 2700 | path_put_conditional(&path, nd); |
2708 | path_put(&nd->path); | 2701 | path_put(&nd->path); |
2709 | filp = ERR_PTR(-ELOOP); | 2702 | res = ERR_PTR(-ELOOP); |
2710 | break; | 2703 | break; |
2711 | } | 2704 | } |
2712 | nd->flags |= LOOKUP_PARENT; | 2705 | nd->flags |= LOOKUP_PARENT; |
@@ -2714,7 +2707,7 @@ static struct file *path_openat(int dfd, const char *pathname, | |||
2714 | error = follow_link(&link, nd, &cookie); | 2707 | error = follow_link(&link, nd, &cookie); |
2715 | if (unlikely(error)) | 2708 | if (unlikely(error)) |
2716 | goto out_filp; | 2709 | goto out_filp; |
2717 | filp = do_last(nd, &path, op, pathname); | 2710 | res = do_last(nd, &path, &od, op, pathname); |
2718 | put_link(nd, &link, cookie); | 2711 | put_link(nd, &link, cookie); |
2719 | } | 2712 | } |
2720 | out: | 2713 | out: |
@@ -2722,17 +2715,20 @@ out: | |||
2722 | path_put(&nd->root); | 2715 | path_put(&nd->root); |
2723 | if (base) | 2716 | if (base) |
2724 | fput(base); | 2717 | fput(base); |
2725 | release_open_intent(nd); | 2718 | if (od.filp) { |
2726 | if (filp == ERR_PTR(-EOPENSTALE)) { | 2719 | BUG_ON(od.filp->f_path.dentry); |
2720 | put_filp(od.filp); | ||
2721 | } | ||
2722 | if (res == ERR_PTR(-EOPENSTALE)) { | ||
2727 | if (flags & LOOKUP_RCU) | 2723 | if (flags & LOOKUP_RCU) |
2728 | filp = ERR_PTR(-ECHILD); | 2724 | res = ERR_PTR(-ECHILD); |
2729 | else | 2725 | else |
2730 | filp = ERR_PTR(-ESTALE); | 2726 | res = ERR_PTR(-ESTALE); |
2731 | } | 2727 | } |
2732 | return filp; | 2728 | return res; |
2733 | 2729 | ||
2734 | out_filp: | 2730 | out_filp: |
2735 | filp = ERR_PTR(error); | 2731 | res = ERR_PTR(error); |
2736 | goto out; | 2732 | goto out; |
2737 | } | 2733 | } |
2738 | 2734 | ||
@@ -2788,7 +2784,6 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path | |||
2788 | goto out; | 2784 | goto out; |
2789 | nd.flags &= ~LOOKUP_PARENT; | 2785 | nd.flags &= ~LOOKUP_PARENT; |
2790 | nd.flags |= LOOKUP_CREATE | LOOKUP_EXCL; | 2786 | nd.flags |= LOOKUP_CREATE | LOOKUP_EXCL; |
2791 | nd.intent.open.flags = O_EXCL; | ||
2792 | 2787 | ||
2793 | /* | 2788 | /* |
2794 | * Do the final lookup. | 2789 | * Do the final lookup. |