@@ -2510,10 +2510,10 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
25102510}
25112511
25122512void
2513- cifs_writedata_release (struct kref * refcount )
2513+ cifs_writedata_release (struct cifs_io_subrequest * wdata )
25142514{
2515- struct cifs_writedata * wdata = container_of ( refcount ,
2516- struct cifs_writedata , refcount );
2515+ if ( wdata -> uncached )
2516+ kref_put ( & wdata -> ctx -> refcount , cifs_aio_ctx_release );
25172517#ifdef CONFIG_CIFS_SMB_DIRECT
25182518 if (wdata -> mr ) {
25192519 smbd_deregister_mr (wdata -> mr );
@@ -2532,7 +2532,7 @@ cifs_writedata_release(struct kref *refcount)
25322532 * possible that the page was redirtied so re-clean the page.
25332533 */
25342534static void
2535- cifs_writev_requeue (struct cifs_writedata * wdata )
2535+ cifs_writev_requeue (struct cifs_io_subrequest * wdata )
25362536{
25372537 int rc = 0 ;
25382538 struct inode * inode = d_inode (wdata -> cfile -> dentry );
@@ -2542,7 +2542,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
25422542
25432543 server = tlink_tcon (wdata -> cfile -> tlink )-> ses -> server ;
25442544 do {
2545- struct cifs_writedata * wdata2 ;
2545+ struct cifs_io_subrequest * wdata2 ;
25462546 unsigned int wsize , cur_len ;
25472547
25482548 wsize = server -> ops -> wp_retry_size (inode );
@@ -2565,7 +2565,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
25652565 wdata2 -> sync_mode = wdata -> sync_mode ;
25662566 wdata2 -> offset = fpos ;
25672567 wdata2 -> bytes = cur_len ;
2568- wdata2 -> iter = wdata -> iter ;
2568+ wdata2 -> iter = wdata -> iter ;
25692569
25702570 iov_iter_advance (& wdata2 -> iter , fpos - wdata -> offset );
25712571 iov_iter_truncate (& wdata2 -> iter , wdata2 -> bytes );
@@ -2587,11 +2587,10 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
25872587 rc = - EBADF ;
25882588 } else {
25892589 wdata2 -> pid = wdata2 -> cfile -> pid ;
2590- rc = server -> ops -> async_writev (wdata2 ,
2591- cifs_writedata_release );
2590+ rc = server -> ops -> async_writev (wdata2 );
25922591 }
25932592
2594- kref_put ( & wdata2 -> refcount , cifs_writedata_release );
2593+ cifs_put_writedata ( wdata2 );
25952594 if (rc ) {
25962595 if (is_retryable_error (rc ))
25972596 continue ;
@@ -2610,14 +2609,14 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
26102609
26112610 if (rc != 0 && !is_retryable_error (rc ))
26122611 mapping_set_error (inode -> i_mapping , rc );
2613- kref_put ( & wdata -> refcount , cifs_writedata_release );
2612+ cifs_put_writedata ( wdata );
26142613}
26152614
26162615void
26172616cifs_writev_complete (struct work_struct * work )
26182617{
2619- struct cifs_writedata * wdata = container_of (work ,
2620- struct cifs_writedata , work );
2618+ struct cifs_io_subrequest * wdata = container_of (work ,
2619+ struct cifs_io_subrequest , work );
26212620 struct inode * inode = d_inode (wdata -> cfile -> dentry );
26222621
26232622 if (wdata -> result == 0 ) {
@@ -2638,16 +2637,16 @@ cifs_writev_complete(struct work_struct *work)
26382637
26392638 if (wdata -> result != - EAGAIN )
26402639 mapping_set_error (inode -> i_mapping , wdata -> result );
2641- kref_put ( & wdata -> refcount , cifs_writedata_release );
2640+ cifs_put_writedata ( wdata );
26422641}
26432642
2644- struct cifs_writedata * cifs_writedata_alloc (work_func_t complete )
2643+ struct cifs_io_subrequest * cifs_writedata_alloc (work_func_t complete )
26452644{
2646- struct cifs_writedata * wdata ;
2645+ struct cifs_io_subrequest * wdata ;
26472646
26482647 wdata = kzalloc (sizeof (* wdata ), GFP_NOFS );
26492648 if (wdata != NULL ) {
2650- kref_init (& wdata -> refcount );
2649+ refcount_set (& wdata -> subreq . ref , 1 );
26512650 INIT_LIST_HEAD (& wdata -> list );
26522651 init_completion (& wdata -> done );
26532652 INIT_WORK (& wdata -> work , complete );
@@ -2778,7 +2777,7 @@ static ssize_t cifs_write_back_from_locked_folio(struct address_space *mapping,
27782777{
27792778 struct inode * inode = mapping -> host ;
27802779 struct TCP_Server_Info * server ;
2781- struct cifs_writedata * wdata ;
2780+ struct cifs_io_subrequest * wdata ;
27822781 struct cifs_sb_info * cifs_sb = CIFS_SB (inode -> i_sb );
27832782 struct cifs_credits credits_on_stack ;
27842783 struct cifs_credits * credits = & credits_on_stack ;
@@ -2871,10 +2870,9 @@ static ssize_t cifs_write_back_from_locked_folio(struct address_space *mapping,
28712870 if (wdata -> cfile -> invalidHandle )
28722871 rc = - EAGAIN ;
28732872 else
2874- rc = wdata -> server -> ops -> async_writev (wdata ,
2875- cifs_writedata_release );
2873+ rc = wdata -> server -> ops -> async_writev (wdata );
28762874 if (rc >= 0 ) {
2877- kref_put ( & wdata -> refcount , cifs_writedata_release );
2875+ cifs_put_writedata ( wdata );
28782876 goto err_close ;
28792877 }
28802878 } else {
@@ -2884,7 +2882,7 @@ static ssize_t cifs_write_back_from_locked_folio(struct address_space *mapping,
28842882 }
28852883
28862884err_wdata :
2887- kref_put ( & wdata -> refcount , cifs_writedata_release );
2885+ cifs_put_writedata ( wdata );
28882886err_uncredit :
28892887 add_credits_and_wake_if (server , credits , 0 );
28902888err_close :
@@ -3261,23 +3259,13 @@ int cifs_flush(struct file *file, fl_owner_t id)
32613259 return rc ;
32623260}
32633261
3264- static void
3265- cifs_uncached_writedata_release (struct kref * refcount )
3266- {
3267- struct cifs_writedata * wdata = container_of (refcount ,
3268- struct cifs_writedata , refcount );
3269-
3270- kref_put (& wdata -> ctx -> refcount , cifs_aio_ctx_release );
3271- cifs_writedata_release (refcount );
3272- }
3273-
32743262static void collect_uncached_write_data (struct cifs_aio_ctx * ctx );
32753263
32763264static void
32773265cifs_uncached_writev_complete (struct work_struct * work )
32783266{
3279- struct cifs_writedata * wdata = container_of (work ,
3280- struct cifs_writedata , work );
3267+ struct cifs_io_subrequest * wdata = container_of (work ,
3268+ struct cifs_io_subrequest , work );
32813269 struct inode * inode = d_inode (wdata -> cfile -> dentry );
32823270 struct cifsInodeInfo * cifsi = CIFS_I (inode );
32833271
@@ -3290,11 +3278,11 @@ cifs_uncached_writev_complete(struct work_struct *work)
32903278 complete (& wdata -> done );
32913279 collect_uncached_write_data (wdata -> ctx );
32923280 /* the below call can possibly free the last ref to aio ctx */
3293- kref_put ( & wdata -> refcount , cifs_uncached_writedata_release );
3281+ cifs_put_writedata ( wdata );
32943282}
32953283
32963284static int
3297- cifs_resend_wdata (struct cifs_writedata * wdata , struct list_head * wdata_list ,
3285+ cifs_resend_wdata (struct cifs_io_subrequest * wdata , struct list_head * wdata_list ,
32983286 struct cifs_aio_ctx * ctx )
32993287{
33003288 unsigned int wsize ;
@@ -3344,8 +3332,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
33443332 wdata -> mr = NULL ;
33453333 }
33463334#endif
3347- rc = server -> ops -> async_writev (wdata ,
3348- cifs_uncached_writedata_release );
3335+ rc = server -> ops -> async_writev (wdata );
33493336 }
33503337 }
33513338
@@ -3360,7 +3347,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
33603347 } while (rc == - EAGAIN );
33613348
33623349fail :
3363- kref_put ( & wdata -> refcount , cifs_uncached_writedata_release );
3350+ cifs_put_writedata ( wdata );
33643351 return rc ;
33653352}
33663353
@@ -3412,7 +3399,7 @@ cifs_write_from_iter(loff_t fpos, size_t len, struct iov_iter *from,
34123399{
34133400 int rc = 0 ;
34143401 size_t cur_len , max_len ;
3415- struct cifs_writedata * wdata ;
3402+ struct cifs_io_subrequest * wdata ;
34163403 pid_t pid ;
34173404 struct TCP_Server_Info * server ;
34183405 unsigned int xid , max_segs = INT_MAX ;
@@ -3476,6 +3463,7 @@ cifs_write_from_iter(loff_t fpos, size_t len, struct iov_iter *from,
34763463 break ;
34773464 }
34783465
3466+ wdata -> uncached = true;
34793467 wdata -> sync_mode = WB_SYNC_ALL ;
34803468 wdata -> offset = (__u64 )fpos ;
34813469 wdata -> cfile = cifsFileInfo_get (open_file );
@@ -3495,14 +3483,12 @@ cifs_write_from_iter(loff_t fpos, size_t len, struct iov_iter *from,
34953483 if (wdata -> cfile -> invalidHandle )
34963484 rc = - EAGAIN ;
34973485 else
3498- rc = server -> ops -> async_writev (wdata ,
3499- cifs_uncached_writedata_release );
3486+ rc = server -> ops -> async_writev (wdata );
35003487 }
35013488
35023489 if (rc ) {
35033490 add_credits_and_wake_if (server , & wdata -> credits , 0 );
3504- kref_put (& wdata -> refcount ,
3505- cifs_uncached_writedata_release );
3491+ cifs_put_writedata (wdata );
35063492 if (rc == - EAGAIN )
35073493 continue ;
35083494 break ;
@@ -3520,7 +3506,7 @@ cifs_write_from_iter(loff_t fpos, size_t len, struct iov_iter *from,
35203506
35213507static void collect_uncached_write_data (struct cifs_aio_ctx * ctx )
35223508{
3523- struct cifs_writedata * wdata , * tmp ;
3509+ struct cifs_io_subrequest * wdata , * tmp ;
35243510 struct cifs_tcon * tcon ;
35253511 struct cifs_sb_info * cifs_sb ;
35263512 struct dentry * dentry = ctx -> cfile -> dentry ;
@@ -3575,16 +3561,15 @@ static void collect_uncached_write_data(struct cifs_aio_ctx *ctx)
35753561 ctx -> cfile , cifs_sb , & tmp_list ,
35763562 ctx );
35773563
3578- kref_put (& wdata -> refcount ,
3579- cifs_uncached_writedata_release );
3564+ cifs_put_writedata (wdata );
35803565 }
35813566
35823567 list_splice (& tmp_list , & ctx -> list );
35833568 goto restart_loop ;
35843569 }
35853570 }
35863571 list_del_init (& wdata -> list );
3587- kref_put ( & wdata -> refcount , cifs_uncached_writedata_release );
3572+ cifs_put_writedata ( wdata );
35883573 }
35893574
35903575 cifs_stats_bytes_written (tcon , ctx -> total_len );
0 commit comments