All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next 0/2] add release callback to cifs_writedata
@ 2022-08-23 13:06 Zhang Xiaoxu
  2022-08-23 13:06 ` [PATCH -next 1/2] cifs: Add release function " Zhang Xiaoxu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 13:06 UTC (permalink / raw)
  To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad,
	rohiths, smfrench

The release function of struct cifs_writedata is determined when its
allocated, so add it to the struct and remove the extra parameter about
async_writev

Zhang Xiaoxu (2):
  cifs: Add release function to cifs_writedata
  cifs: remove the release parameter form async_writev

 fs/cifs/cifsglob.h  |  4 ++--
 fs/cifs/cifsproto.h |  9 +++----
 fs/cifs/cifssmb.c   |  5 ++--
 fs/cifs/file.c      | 58 +++++++++++++++++++++++----------------------
 fs/cifs/smb2pdu.c   |  5 ++--
 fs/cifs/smb2proto.h |  3 +--
 6 files changed, 42 insertions(+), 42 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH -next 1/2] cifs: Add release function to cifs_writedata
  2022-08-23 13:06 [PATCH -next 0/2] add release callback to cifs_writedata Zhang Xiaoxu
@ 2022-08-23 13:06 ` Zhang Xiaoxu
  2022-08-23 13:06 ` [PATCH -next 2/2] cifs: remove the release parameter form async_writev Zhang Xiaoxu
  2022-08-23 17:57 ` [PATCH -next 0/2] add release callback to cifs_writedata Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 13:06 UTC (permalink / raw)
  To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad,
	rohiths, smfrench

The release function is determined when init the cifs_writedata,
so add it to the struct cifs_writedata.

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/cifs/cifsglob.h  |  1 +
 fs/cifs/cifsproto.h |  6 +++--
 fs/cifs/file.c      | 57 ++++++++++++++++++++++++---------------------
 3 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index f15d7b0c123d..19223df189d0 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1459,6 +1459,7 @@ struct cifs_readdata {
 /* asynchronous write support */
 struct cifs_writedata {
 	struct kref			refcount;
+	void				(*release)(struct kref *arg);
 	struct list_head		list;
 	struct completion		done;
 	enum writeback_sync_modes	sync_mode;
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 3bc94bcc7177..10890c0c0910 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -577,9 +577,11 @@ int cifs_async_writev(struct cifs_writedata *wdata,
 		      void (*release)(struct kref *kref));
 void cifs_writev_complete(struct work_struct *work);
 struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
-						work_func_t complete);
+					    work_func_t complete,
+					    void (*release)(struct kref *));
 struct cifs_writedata *cifs_writedata_direct_alloc(struct page **pages,
-						work_func_t complete);
+						work_func_t complete,
+						void (*release)(struct kref *));
 void cifs_writedata_release(struct kref *refcount);
 int cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
 			  struct cifs_sb_info *cifs_sb,
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index fa738adc031f..56d1b28fb476 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2327,7 +2327,9 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 			tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE;
 		}
 
-		wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete);
+		wdata2 = cifs_writedata_alloc(nr_pages,
+					      cifs_writev_complete,
+					      cifs_writedata_release);
 		if (!wdata2) {
 			rc = -ENOMEM;
 			break;
@@ -2355,8 +2357,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 				rc = -EBADF;
 		} else {
 			wdata2->pid = wdata2->cfile->pid;
-			rc = server->ops->async_writev(wdata2,
-						       cifs_writedata_release);
+			rc = server->ops->async_writev(wdata2, wdata2->release);
 		}
 
 		for (j = 0; j < nr_pages; j++) {
@@ -2368,7 +2369,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 			}
 		}
 
-		kref_put(&wdata2->refcount, cifs_writedata_release);
+		kref_put(&wdata2->refcount, wdata2->release);
 		if (rc) {
 			if (is_retryable_error(rc))
 				continue;
@@ -2389,7 +2390,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 
 	if (rc != 0 && !is_retryable_error(rc))
 		mapping_set_error(inode->i_mapping, rc);
-	kref_put(&wdata->refcount, cifs_writedata_release);
+	kref_put(&wdata->refcount, wdata->release);
 }
 
 void
@@ -2422,28 +2423,31 @@ cifs_writev_complete(struct work_struct *work)
 	}
 	if (wdata->result != -EAGAIN)
 		mapping_set_error(inode->i_mapping, wdata->result);
-	kref_put(&wdata->refcount, cifs_writedata_release);
+	kref_put(&wdata->refcount, wdata->release);
 }
 
 struct cifs_writedata *
-cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
+cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete,
+		     void (*release)(struct kref *))
 {
 	struct page **pages =
 		kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
 	if (pages)
-		return cifs_writedata_direct_alloc(pages, complete);
+		return cifs_writedata_direct_alloc(pages, complete, release);
 
 	return NULL;
 }
 
 struct cifs_writedata *
-cifs_writedata_direct_alloc(struct page **pages, work_func_t complete)
+cifs_writedata_direct_alloc(struct page **pages, work_func_t complete,
+			    void (*release)(struct kref *))
 {
 	struct cifs_writedata *wdata;
 
 	wdata = kzalloc(sizeof(*wdata), GFP_NOFS);
 	if (wdata != NULL) {
 		wdata->pages = pages;
+		wdata->release = release;
 		kref_init(&wdata->refcount);
 		INIT_LIST_HEAD(&wdata->list);
 		init_completion(&wdata->done);
@@ -2519,7 +2523,8 @@ wdata_alloc_and_fillpages(pgoff_t tofind, struct address_space *mapping,
 	struct cifs_writedata *wdata;
 
 	wdata = cifs_writedata_alloc((unsigned int)tofind,
-				     cifs_writev_complete);
+				     cifs_writev_complete,
+				     cifs_writedata_release);
 	if (!wdata)
 		return NULL;
 
@@ -2630,8 +2635,7 @@ wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages,
 	if (wdata->cfile->invalidHandle)
 		rc = -EAGAIN;
 	else
-		rc = wdata->server->ops->async_writev(wdata,
-						      cifs_writedata_release);
+		rc = wdata->server->ops->async_writev(wdata, wdata->release);
 
 	return rc;
 }
@@ -2706,7 +2710,7 @@ static int cifs_writepages(struct address_space *mapping,
 		}
 
 		if (found_pages == 0) {
-			kref_put(&wdata->refcount, cifs_writedata_release);
+			kref_put(&wdata->refcount, wdata->release);
 			add_credits_and_wake_if(server, credits, 0);
 			break;
 		}
@@ -2716,7 +2720,7 @@ static int cifs_writepages(struct address_space *mapping,
 
 		/* nothing to write? */
 		if (nr_pages == 0) {
-			kref_put(&wdata->refcount, cifs_writedata_release);
+			kref_put(&wdata->refcount, wdata->release);
 			add_credits_and_wake_if(server, credits, 0);
 			continue;
 		}
@@ -2754,7 +2758,7 @@ static int cifs_writepages(struct address_space *mapping,
 			if (!is_retryable_error(rc))
 				mapping_set_error(mapping, rc);
 		}
-		kref_put(&wdata->refcount, cifs_writedata_release);
+		kref_put(&wdata->refcount, wdata->release);
 
 		if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN) {
 			index = saved_index;
@@ -3107,7 +3111,7 @@ cifs_uncached_writev_complete(struct work_struct *work)
 	complete(&wdata->done);
 	collect_uncached_write_data(wdata->ctx);
 	/* the below call can possibly free the last ref to aio ctx */
-	kref_put(&wdata->refcount, cifs_uncached_writedata_release);
+	kref_put(&wdata->refcount, wdata->release);
 }
 
 static int
@@ -3203,7 +3207,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
 				}
 #endif
 				rc = server->ops->async_writev(wdata,
-					cifs_uncached_writedata_release);
+							       wdata->release);
 			}
 		}
 
@@ -3218,7 +3222,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
 	} while (rc == -EAGAIN);
 
 fail:
-	kref_put(&wdata->refcount, cifs_uncached_writedata_release);
+	kref_put(&wdata->refcount, wdata->release);
 	return rc;
 }
 
@@ -3290,7 +3294,8 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 				(cur_len + start + PAGE_SIZE - 1) / PAGE_SIZE;
 
 			wdata = cifs_writedata_direct_alloc(pagevec,
-					     cifs_uncached_writev_complete);
+					     cifs_uncached_writev_complete,
+					     cifs_uncached_writedata_release);
 			if (!wdata) {
 				rc = -ENOMEM;
 				add_credits_and_wake_if(server, credits, 0);
@@ -3307,7 +3312,8 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 		} else {
 			nr_pages = get_numpages(wsize, len, &cur_len);
 			wdata = cifs_writedata_alloc(nr_pages,
-					     cifs_uncached_writev_complete);
+					     cifs_uncached_writev_complete,
+					     cifs_uncached_writedata_release);
 			if (!wdata) {
 				rc = -ENOMEM;
 				add_credits_and_wake_if(server, credits, 0);
@@ -3362,14 +3368,12 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 			if (wdata->cfile->invalidHandle)
 				rc = -EAGAIN;
 			else
-				rc = server->ops->async_writev(wdata,
-					cifs_uncached_writedata_release);
+				rc = server->ops->async_writev(wdata, wdata->release);
 		}
 
 		if (rc) {
 			add_credits_and_wake_if(server, &wdata->credits, 0);
-			kref_put(&wdata->refcount,
-				 cifs_uncached_writedata_release);
+			kref_put(&wdata->refcount, wdata->release);
 			if (rc == -EAGAIN) {
 				*from = saved_from;
 				iov_iter_advance(from, offset - saved_offset);
@@ -3444,8 +3448,7 @@ static void collect_uncached_write_data(struct cifs_aio_ctx *ctx)
 						ctx->cfile, cifs_sb, &tmp_list,
 						ctx);
 
-					kref_put(&wdata->refcount,
-						cifs_uncached_writedata_release);
+					kref_put(&wdata->refcount, wdata->release);
 				}
 
 				list_splice(&tmp_list, &ctx->list);
@@ -3453,7 +3456,7 @@ static void collect_uncached_write_data(struct cifs_aio_ctx *ctx)
 			}
 		}
 		list_del_init(&wdata->list);
-		kref_put(&wdata->refcount, cifs_uncached_writedata_release);
+		kref_put(&wdata->refcount, wdata->release);
 	}
 
 	cifs_stats_bytes_written(tcon, ctx->total_len);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH -next 2/2] cifs: remove the release parameter form async_writev
  2022-08-23 13:06 [PATCH -next 0/2] add release callback to cifs_writedata Zhang Xiaoxu
  2022-08-23 13:06 ` [PATCH -next 1/2] cifs: Add release function " Zhang Xiaoxu
@ 2022-08-23 13:06 ` Zhang Xiaoxu
  2022-08-23 17:57 ` [PATCH -next 0/2] add release callback to cifs_writedata Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 13:06 UTC (permalink / raw)
  To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad,
	rohiths, smfrench

Release function can get directly from writedata, so remove this
parameter from async_writev function.

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/cifs/cifsglob.h  | 3 +--
 fs/cifs/cifsproto.h | 3 +--
 fs/cifs/cifssmb.c   | 5 ++---
 fs/cifs/file.c      | 9 ++++-----
 fs/cifs/smb2pdu.c   | 5 ++---
 fs/cifs/smb2proto.h | 3 +--
 6 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 19223df189d0..187b32158da8 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -394,8 +394,7 @@ struct smb_version_operations {
 	/* async read from the server */
 	int (*async_readv)(struct cifs_readdata *);
 	/* async write to the server */
-	int (*async_writev)(struct cifs_writedata *,
-			    void (*release)(struct kref *));
+	int (*async_writev)(struct cifs_writedata *);
 	/* sync read from the server */
 	int (*sync_read)(const unsigned int, struct cifs_fid *,
 			 struct cifs_io_parms *, unsigned int *, char **,
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 10890c0c0910..f71b8141126b 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -573,8 +573,7 @@ void cifs_readdata_release(struct kref *refcount);
 int cifs_async_readv(struct cifs_readdata *rdata);
 int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid);
 
-int cifs_async_writev(struct cifs_writedata *wdata,
-		      void (*release)(struct kref *kref));
+int cifs_async_writev(struct cifs_writedata *wdata);
 void cifs_writev_complete(struct work_struct *work);
 struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
 					    work_func_t complete,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 7aa91e272027..f562cb0f648a 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1690,8 +1690,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
 
 /* cifs_async_writev - send an async write, and set up mid to handle result */
 int
-cifs_async_writev(struct cifs_writedata *wdata,
-		  void (*release)(struct kref *kref))
+cifs_async_writev(struct cifs_writedata *wdata)
 {
 	int rc = -EACCES;
 	WRITE_REQ *smb = NULL;
@@ -1768,7 +1767,7 @@ cifs_async_writev(struct cifs_writedata *wdata,
 	if (rc == 0)
 		cifs_stats_inc(&tcon->stats.cifs_stats.num_writes);
 	else
-		kref_put(&wdata->refcount, release);
+		kref_put(&wdata->refcount, wdata->release);
 
 async_writev_out:
 	cifs_small_buf_release(smb);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 56d1b28fb476..69fb59d86721 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2357,7 +2357,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
 				rc = -EBADF;
 		} else {
 			wdata2->pid = wdata2->cfile->pid;
-			rc = server->ops->async_writev(wdata2, wdata2->release);
+			rc = server->ops->async_writev(wdata2);
 		}
 
 		for (j = 0; j < nr_pages; j++) {
@@ -2635,7 +2635,7 @@ wdata_send_pages(struct cifs_writedata *wdata, unsigned int nr_pages,
 	if (wdata->cfile->invalidHandle)
 		rc = -EAGAIN;
 	else
-		rc = wdata->server->ops->async_writev(wdata, wdata->release);
+		rc = wdata->server->ops->async_writev(wdata);
 
 	return rc;
 }
@@ -3206,8 +3206,7 @@ cifs_resend_wdata(struct cifs_writedata *wdata, struct list_head *wdata_list,
 					wdata->mr = NULL;
 				}
 #endif
-				rc = server->ops->async_writev(wdata,
-							       wdata->release);
+				rc = server->ops->async_writev(wdata);
 			}
 		}
 
@@ -3368,7 +3367,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
 			if (wdata->cfile->invalidHandle)
 				rc = -EAGAIN;
 			else
-				rc = server->ops->async_writev(wdata, wdata->release);
+				rc = server->ops->async_writev(wdata);
 		}
 
 		if (rc) {
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 9b31ea946d45..c89f9253884e 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -4447,8 +4447,7 @@ smb2_writev_callback(struct mid_q_entry *mid)
 
 /* smb2_async_writev - send an async write, and set up mid to handle result */
 int
-smb2_async_writev(struct cifs_writedata *wdata,
-		  void (*release)(struct kref *kref))
+smb2_async_writev(struct cifs_writedata *wdata)
 {
 	int rc = -EACCES, flags = 0;
 	struct smb2_write_req *req = NULL;
@@ -4575,7 +4574,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
 				     req->PersistentFileId,
 				     tcon->tid, tcon->ses->Suid, wdata->offset,
 				     wdata->bytes, rc);
-		kref_put(&wdata->refcount, release);
+		kref_put(&wdata->refcount, wdata->release);
 		cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
 	}
 
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
index 08f243757b9b..a478267c58ac 100644
--- a/fs/cifs/smb2proto.h
+++ b/fs/cifs/smb2proto.h
@@ -190,8 +190,7 @@ extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
 extern int smb2_async_readv(struct cifs_readdata *rdata);
 extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
 		     unsigned int *nbytes, char **buf, int *buf_type);
-extern int smb2_async_writev(struct cifs_writedata *wdata,
-			     void (*release)(struct kref *kref));
+extern int smb2_async_writev(struct cifs_writedata *wdata);
 extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 		      unsigned int *nbytes, struct kvec *iov, int n_vec);
 extern int SMB2_echo(struct TCP_Server_Info *server);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next 0/2] add release callback to cifs_writedata
  2022-08-23 13:06 [PATCH -next 0/2] add release callback to cifs_writedata Zhang Xiaoxu
  2022-08-23 13:06 ` [PATCH -next 1/2] cifs: Add release function " Zhang Xiaoxu
  2022-08-23 13:06 ` [PATCH -next 2/2] cifs: remove the release parameter form async_writev Zhang Xiaoxu
@ 2022-08-23 17:57 ` Paulo Alcantara
  2 siblings, 0 replies; 4+ messages in thread
From: Paulo Alcantara @ 2022-08-23 17:57 UTC (permalink / raw)
  To: Zhang Xiaoxu, linux-cifs, zhangxiaoxu5, sfrench, lsahlber,
	sprasad, rohiths, smfrench

Zhang Xiaoxu <zhangxiaoxu5@huawei.com> writes:

> The release function of struct cifs_writedata is determined when its
> allocated, so add it to the struct and remove the extra parameter about
> async_writev
>
> Zhang Xiaoxu (2):
>   cifs: Add release function to cifs_writedata
>   cifs: remove the release parameter form async_writev
>
>  fs/cifs/cifsglob.h  |  4 ++--
>  fs/cifs/cifsproto.h |  9 +++----
>  fs/cifs/cifssmb.c   |  5 ++--
>  fs/cifs/file.c      | 58 +++++++++++++++++++++++----------------------
>  fs/cifs/smb2pdu.c   |  5 ++--
>  fs/cifs/smb2proto.h |  3 +--
>  6 files changed, 42 insertions(+), 42 deletions(-)

Acked-by: Paulo Alcantara (SUSE) <pc@cjr.nz>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-23 19:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 13:06 [PATCH -next 0/2] add release callback to cifs_writedata Zhang Xiaoxu
2022-08-23 13:06 ` [PATCH -next 1/2] cifs: Add release function " Zhang Xiaoxu
2022-08-23 13:06 ` [PATCH -next 2/2] cifs: remove the release parameter form async_writev Zhang Xiaoxu
2022-08-23 17:57 ` [PATCH -next 0/2] add release callback to cifs_writedata Paulo Alcantara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.