Commit 87fba18a authored by David Howells's avatar David Howells Committed by Steve French
Browse files

cifs: Remove the server pointer from smb_message



Remove the server pointer from smb_message and instead pass it down to all
the things that access it.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarPaulo Alcantara (Red Hat) <pc@manguebit.org>
cc: Shyam Prasad N <sprasad@microsoft.com>
cc: Tom Talpey <tom@talpey.com> (RDMA, smbdirect)
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 6a86a4cc
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ static struct kmem_cache *cifs_io_request_cachep;
static struct kmem_cache *cifs_io_subrequest_cachep;
mempool_t *cifs_sm_req_poolp;
mempool_t *cifs_req_poolp;
mempool_t *cifs_mid_poolp;
mempool_t cifs_mid_pool;
mempool_t cifs_io_request_pool;
mempool_t cifs_io_subrequest_pool;

@@ -1846,8 +1846,7 @@ static int init_mids(void)
		return -ENOMEM;

	/* 3 is a reasonable minimum number of simultaneous operations */
	cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
	if (cifs_mid_poolp == NULL) {
	if (mempool_init_slab_pool(&cifs_mid_pool, 3, cifs_mid_cachep) < 0) {
		kmem_cache_destroy(cifs_mid_cachep);
		return -ENOMEM;
	}
@@ -1857,7 +1856,7 @@ static int init_mids(void)

static void destroy_mids(void)
{
	mempool_destroy(cifs_mid_poolp);
	mempool_exit(&cifs_mid_pool);
	kmem_cache_destroy(cifs_mid_cachep);
}

+7 −7
Original line number Diff line number Diff line
@@ -1671,7 +1671,7 @@ typedef int (*mid_receive_t)(struct TCP_Server_Info *server,
 * - it will be called by cifsd, with no locks held
 * - the mid will be removed from any lists
 */
typedef void (*mid_callback_t)(struct mid_q_entry *mid);
typedef void (*mid_callback_t)(struct TCP_Server_Info *srv, struct mid_q_entry *mid);

/*
 * This is the protopyte for mid handle function. This is called once the mid
@@ -1683,8 +1683,7 @@ typedef int (*mid_handle_t)(struct TCP_Server_Info *server,
/* one of these for every pending CIFS request to the server */
struct mid_q_entry {
	struct list_head qhead;	/* mids waiting on reply from this server */
	struct kref refcount;
	struct TCP_Server_Info *server;	/* server corresponding to this mid */
	refcount_t refcount;
	__u64 mid;		/* multiplex id */
	__u16 credits;		/* number of credits consumed by this mid */
	__u16 credits_received;	/* number of credits from the response */
@@ -2109,7 +2108,7 @@ extern __u32 cifs_lock_secret;

extern mempool_t *cifs_sm_req_poolp;
extern mempool_t *cifs_req_poolp;
extern mempool_t *cifs_mid_poolp;
extern mempool_t cifs_mid_pool;
extern mempool_t cifs_io_request_pool;
extern mempool_t cifs_io_subrequest_pool;

@@ -2356,9 +2355,10 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen)
 * Execute mid callback atomically - ensures callback runs exactly once
 * and prevents sleeping in atomic context.
 */
static inline void mid_execute_callback(struct mid_q_entry *mid)
static inline void mid_execute_callback(struct TCP_Server_Info *server,
					struct mid_q_entry *mid)
{
	void (*callback)(struct mid_q_entry *mid);
	mid_callback_t callback;

	spin_lock(&mid->mid_lock);
	callback = mid->callback;
@@ -2366,7 +2366,7 @@ static inline void mid_execute_callback(struct mid_q_entry *mid)
	spin_unlock(&mid->mid_lock);

	if (callback)
		callback(mid);
		callback(server, mid);
}

#define CIFS_REPARSE_SUPPORT(tcon) \
+14 −7
Original line number Diff line number Diff line
@@ -82,9 +82,9 @@ extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx,
				     int add_treename);
extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
char *cifs_build_devname(char *nodename, const char *prepath);
extern void delete_mid(struct mid_q_entry *mid);
void __release_mid(struct kref *refcount);
extern void cifs_wake_up_task(struct mid_q_entry *mid);
void delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid);
void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid);
void cifs_wake_up_task(struct TCP_Server_Info *server, struct mid_q_entry *mid);
extern int cifs_handle_standard(struct TCP_Server_Info *server,
				struct mid_q_entry *mid);
extern char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx,
@@ -180,7 +180,8 @@ extern int decode_negTokenInit(unsigned char *security_blob, int length,
extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
extern int map_smb_to_linux_error(char *buf, bool logErr);
extern int map_and_check_smb_error(struct mid_q_entry *mid, bool logErr);
extern int map_and_check_smb_error(struct TCP_Server_Info *server,
				   struct mid_q_entry *mid, bool logErr);
unsigned int header_assemble(struct smb_hdr *buffer, char smb_command,
			     const struct cifs_tcon *treeCon, int word_count
			     /* length of fixed section word count in two byte units  */);
@@ -263,7 +264,7 @@ extern unsigned int setup_special_mode_ACE(struct smb_ace *pace,
					   __u64 nmode);
extern unsigned int setup_special_user_owner_ACE(struct smb_ace *pace);

extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
void dequeue_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid, bool malformed);
extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
			         unsigned int to_read);
extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server,
@@ -767,9 +768,15 @@ static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)
	return true;
}

static inline void release_mid(struct mid_q_entry *mid)
static inline void smb_get_mid(struct mid_q_entry *mid)
{
	kref_put(&mid->refcount, __release_mid);
	refcount_inc(&mid->refcount);
}

static inline void release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
	if (refcount_dec_and_test(&mid->refcount))
		__release_mid(server, mid);
}

static inline void cifs_free_open_info(struct cifs_open_info_data *data)
+6 −9
Original line number Diff line number Diff line
@@ -584,12 +584,11 @@ CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon)
 * FIXME: maybe we should consider checking that the reply matches request?
 */
static void
cifs_echo_callback(struct mid_q_entry *mid)
cifs_echo_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
	struct TCP_Server_Info *server = mid->callback_data;
	struct cifs_credits credits = { .value = 1, .instance = 0 };

	release_mid(mid);
	release_mid(server, mid);
	add_credits(server, &credits, CIFS_ECHO_OP);
}

@@ -1317,12 +1316,11 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,
}

static void
cifs_readv_callback(struct mid_q_entry *mid)
cifs_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
	struct cifs_io_subrequest *rdata = mid->callback_data;
	struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode);
	struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink);
	struct TCP_Server_Info *server = tcon->ses->server;
	struct smb_rqst rqst = { .rq_iov = rdata->iov,
				 .rq_nvec = 1,
				 .rq_iter = rdata->subreq.io_iter };
@@ -1420,7 +1418,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
	rdata->subreq.transferred += rdata->got_bytes;
	trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_progress);
	netfs_read_subreq_terminated(&rdata->subreq);
	release_mid(mid);
	release_mid(server, mid);
	add_credits(server, &credits, 0);
	trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, 0,
			      server->credits, server->in_flight,
@@ -1736,10 +1734,9 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
 * workqueue completion task.
 */
static void
cifs_writev_callback(struct mid_q_entry *mid)
cifs_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
	struct cifs_io_subrequest *wdata = mid->callback_data;
	struct TCP_Server_Info *server = wdata->server;
	struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink);
	WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf;
	struct cifs_credits credits = {
@@ -1803,7 +1800,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
			      0, cifs_trace_rw_credits_write_response_clear);
	wdata->credits.value = 0;
	cifs_write_subrequest_terminated(wdata, result);
	release_mid(mid);
	release_mid(server, mid);
	trace_smb3_rw_credits(credits.rreq_debug_id, credits.rreq_debug_index, 0,
			      server->credits, server->in_flight,
			      credits.value, cifs_trace_rw_credits_write_response_add);
+7 −8
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
		return NULL;
	}

	temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS);
	temp = mempool_alloc(&cifs_mid_pool, GFP_NOFS);
	memset(temp, 0, sizeof(struct mid_q_entry));
	kref_init(&temp->refcount);
	refcount_set(&temp->refcount, 1);
	spin_lock_init(&temp->mid_lock);
	temp->mid = get_mid(smb_buffer);
	temp->pid = current->pid;
@@ -54,7 +54,6 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
	/* easier to use jiffies */
	/* when mid allocated can be before when sent */
	temp->when_alloc = jiffies;
	temp->server = server;

	/*
	 * The default is for the mid to be synchronous, so the
@@ -119,7 +118,7 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)

	rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
	if (rc) {
		release_mid(mid);
		release_mid(server, mid);
		return ERR_PTR(rc);
	}

@@ -179,11 +178,11 @@ cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
	}

	/* BB special case reconnect tid and uid here? */
	return map_and_check_smb_error(mid, log_error);
	return map_and_check_smb_error(server, mid, log_error);
}

struct mid_q_entry *
cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored,
cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server,
		   struct smb_rqst *rqst)
{
	int rc;
@@ -193,9 +192,9 @@ cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored,
	rc = allocate_mid(ses, hdr, &mid);
	if (rc)
		return ERR_PTR(rc);
	rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number);
	rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
	if (rc) {
		delete_mid(mid);
		delete_mid(server, mid);
		return ERR_PTR(rc);
	}
	return mid;
Loading