@@ -2990,26 +2990,21 @@ static int io_fallocate(struct io_kiocb *req, bool force_nonblock)
2990
2990
return 0 ;
2991
2991
}
2992
2992
2993
- static int io_openat_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe )
2993
+ static int __io_openat_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe )
2994
2994
{
2995
2995
const char __user * fname ;
2996
- u64 flags , mode ;
2997
2996
int ret ;
2998
2997
2999
2998
if (unlikely (req -> ctx -> flags & (IORING_SETUP_IOPOLL |IORING_SETUP_SQPOLL )))
3000
2999
return - EINVAL ;
3001
- if (sqe -> ioprio || sqe -> buf_index )
3000
+ if (unlikely ( sqe -> ioprio || sqe -> buf_index ) )
3002
3001
return - EINVAL ;
3003
- if (req -> flags & REQ_F_FIXED_FILE )
3002
+ if (unlikely ( req -> flags & REQ_F_FIXED_FILE ) )
3004
3003
return - EBADF ;
3005
- if (req -> flags & REQ_F_NEED_CLEANUP )
3006
- return 0 ;
3007
3004
3008
- mode = READ_ONCE (sqe -> len );
3009
- flags = READ_ONCE (sqe -> open_flags );
3010
- if (force_o_largefile ())
3011
- flags |= O_LARGEFILE ;
3012
- req -> open .how = build_open_how (flags , mode );
3005
+ /* open.how should be already initialised */
3006
+ if (!(req -> open .how .flags & O_PATH ) && force_o_largefile ())
3007
+ req -> open .how .flags |= O_LARGEFILE ;
3013
3008
3014
3009
req -> open .dfd = READ_ONCE (sqe -> fd );
3015
3010
fname = u64_to_user_ptr (READ_ONCE (sqe -> addr ));
@@ -3019,33 +3014,33 @@ static int io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3019
3014
req -> open .filename = NULL ;
3020
3015
return ret ;
3021
3016
}
3022
-
3023
3017
req -> open .nofile = rlimit (RLIMIT_NOFILE );
3024
3018
req -> flags |= REQ_F_NEED_CLEANUP ;
3025
3019
return 0 ;
3026
3020
}
3027
3021
3022
+ static int io_openat_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe )
3023
+ {
3024
+ u64 flags , mode ;
3025
+
3026
+ if (req -> flags & REQ_F_NEED_CLEANUP )
3027
+ return 0 ;
3028
+ mode = READ_ONCE (sqe -> len );
3029
+ flags = READ_ONCE (sqe -> open_flags );
3030
+ req -> open .how = build_open_how (flags , mode );
3031
+ return __io_openat_prep (req , sqe );
3032
+ }
3033
+
3028
3034
static int io_openat2_prep (struct io_kiocb * req , const struct io_uring_sqe * sqe )
3029
3035
{
3030
3036
struct open_how __user * how ;
3031
- const char __user * fname ;
3032
3037
size_t len ;
3033
3038
int ret ;
3034
3039
3035
- if (unlikely (req -> ctx -> flags & (IORING_SETUP_IOPOLL |IORING_SETUP_SQPOLL )))
3036
- return - EINVAL ;
3037
- if (sqe -> ioprio || sqe -> buf_index )
3038
- return - EINVAL ;
3039
- if (req -> flags & REQ_F_FIXED_FILE )
3040
- return - EBADF ;
3041
3040
if (req -> flags & REQ_F_NEED_CLEANUP )
3042
3041
return 0 ;
3043
-
3044
- req -> open .dfd = READ_ONCE (sqe -> fd );
3045
- fname = u64_to_user_ptr (READ_ONCE (sqe -> addr ));
3046
3042
how = u64_to_user_ptr (READ_ONCE (sqe -> addr2 ));
3047
3043
len = READ_ONCE (sqe -> len );
3048
-
3049
3044
if (len < OPEN_HOW_SIZE_VER0 )
3050
3045
return - EINVAL ;
3051
3046
@@ -3054,19 +3049,7 @@ static int io_openat2_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3054
3049
if (ret )
3055
3050
return ret ;
3056
3051
3057
- if (!(req -> open .how .flags & O_PATH ) && force_o_largefile ())
3058
- req -> open .how .flags |= O_LARGEFILE ;
3059
-
3060
- req -> open .filename = getname (fname );
3061
- if (IS_ERR (req -> open .filename )) {
3062
- ret = PTR_ERR (req -> open .filename );
3063
- req -> open .filename = NULL ;
3064
- return ret ;
3065
- }
3066
-
3067
- req -> open .nofile = rlimit (RLIMIT_NOFILE );
3068
- req -> flags |= REQ_F_NEED_CLEANUP ;
3069
- return 0 ;
3052
+ return __io_openat_prep (req , sqe );
3070
3053
}
3071
3054
3072
3055
static int io_openat2 (struct io_kiocb * req , bool force_nonblock )
0 commit comments