Skip to content

Commit 87fba18

Browse files
dhowellssmfrench
authored andcommitted
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: David Howells <dhowells@redhat.com> Reviewed-by: Paulo 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: Steve French <stfrench@microsoft.com>
1 parent 6a86a4c commit 87fba18

12 files changed

Lines changed: 108 additions & 113 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static struct kmem_cache *cifs_io_request_cachep;
442442
static struct kmem_cache *cifs_io_subrequest_cachep;
443443
mempool_t *cifs_sm_req_poolp;
444444
mempool_t *cifs_req_poolp;
445-
mempool_t *cifs_mid_poolp;
445+
mempool_t cifs_mid_pool;
446446
mempool_t cifs_io_request_pool;
447447
mempool_t cifs_io_subrequest_pool;
448448

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

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

18581857
static void destroy_mids(void)
18591858
{
1860-
mempool_destroy(cifs_mid_poolp);
1859+
mempool_exit(&cifs_mid_pool);
18611860
kmem_cache_destroy(cifs_mid_cachep);
18621861
}
18631862

fs/smb/client/cifsglob.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ typedef int (*mid_receive_t)(struct TCP_Server_Info *server,
16711671
* - it will be called by cifsd, with no locks held
16721672
* - the mid will be removed from any lists
16731673
*/
1674-
typedef void (*mid_callback_t)(struct mid_q_entry *mid);
1674+
typedef void (*mid_callback_t)(struct TCP_Server_Info *srv, struct mid_q_entry *mid);
16751675

16761676
/*
16771677
* 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,
16831683
/* one of these for every pending CIFS request to the server */
16841684
struct mid_q_entry {
16851685
struct list_head qhead; /* mids waiting on reply from this server */
1686-
struct kref refcount;
1687-
struct TCP_Server_Info *server; /* server corresponding to this mid */
1686+
refcount_t refcount;
16881687
__u64 mid; /* multiplex id */
16891688
__u16 credits; /* number of credits consumed by this mid */
16901689
__u16 credits_received; /* number of credits from the response */
@@ -2109,7 +2108,7 @@ extern __u32 cifs_lock_secret;
21092108

21102109
extern mempool_t *cifs_sm_req_poolp;
21112110
extern mempool_t *cifs_req_poolp;
2112-
extern mempool_t *cifs_mid_poolp;
2111+
extern mempool_t cifs_mid_pool;
21132112
extern mempool_t cifs_io_request_pool;
21142113
extern mempool_t cifs_io_subrequest_pool;
21152114

@@ -2356,17 +2355,18 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen)
23562355
* Execute mid callback atomically - ensures callback runs exactly once
23572356
* and prevents sleeping in atomic context.
23582357
*/
2359-
static inline void mid_execute_callback(struct mid_q_entry *mid)
2358+
static inline void mid_execute_callback(struct TCP_Server_Info *server,
2359+
struct mid_q_entry *mid)
23602360
{
2361-
void (*callback)(struct mid_q_entry *mid);
2361+
mid_callback_t callback;
23622362

23632363
spin_lock(&mid->mid_lock);
23642364
callback = mid->callback;
23652365
mid->callback = NULL; /* Mark as executed, */
23662366
spin_unlock(&mid->mid_lock);
23672367

23682368
if (callback)
2369-
callback(mid);
2369+
callback(server, mid);
23702370
}
23712371

23722372
#define CIFS_REPARSE_SUPPORT(tcon) \

fs/smb/client/cifsproto.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx,
8282
int add_treename);
8383
extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
8484
char *cifs_build_devname(char *nodename, const char *prepath);
85-
extern void delete_mid(struct mid_q_entry *mid);
86-
void __release_mid(struct kref *refcount);
87-
extern void cifs_wake_up_task(struct mid_q_entry *mid);
85+
void delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid);
86+
void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid);
87+
void cifs_wake_up_task(struct TCP_Server_Info *server, struct mid_q_entry *mid);
8888
extern int cifs_handle_standard(struct TCP_Server_Info *server,
8989
struct mid_q_entry *mid);
9090
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,
180180
extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
181181
extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
182182
extern int map_smb_to_linux_error(char *buf, bool logErr);
183-
extern int map_and_check_smb_error(struct mid_q_entry *mid, bool logErr);
183+
extern int map_and_check_smb_error(struct TCP_Server_Info *server,
184+
struct mid_q_entry *mid, bool logErr);
184185
unsigned int header_assemble(struct smb_hdr *buffer, char smb_command,
185186
const struct cifs_tcon *treeCon, int word_count
186187
/* 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,
263264
__u64 nmode);
264265
extern unsigned int setup_special_user_owner_ACE(struct smb_ace *pace);
265266

266-
extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
267+
void dequeue_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid, bool malformed);
267268
extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
268269
unsigned int to_read);
269270
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)
767768
return true;
768769
}
769770

770-
static inline void release_mid(struct mid_q_entry *mid)
771+
static inline void smb_get_mid(struct mid_q_entry *mid)
771772
{
772-
kref_put(&mid->refcount, __release_mid);
773+
refcount_inc(&mid->refcount);
774+
}
775+
776+
static inline void release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid)
777+
{
778+
if (refcount_dec_and_test(&mid->refcount))
779+
__release_mid(server, mid);
773780
}
774781

775782
static inline void cifs_free_open_info(struct cifs_open_info_data *data)

fs/smb/client/cifssmb.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,11 @@ CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon)
584584
* FIXME: maybe we should consider checking that the reply matches request?
585585
*/
586586
static void
587-
cifs_echo_callback(struct mid_q_entry *mid)
587+
cifs_echo_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
588588
{
589-
struct TCP_Server_Info *server = mid->callback_data;
590589
struct cifs_credits credits = { .value = 1, .instance = 0 };
591590

592-
release_mid(mid);
591+
release_mid(server, mid);
593592
add_credits(server, &credits, CIFS_ECHO_OP);
594593
}
595594

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

13191318
static void
1320-
cifs_readv_callback(struct mid_q_entry *mid)
1319+
cifs_readv_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
13211320
{
13221321
struct cifs_io_subrequest *rdata = mid->callback_data;
13231322
struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode);
13241323
struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink);
1325-
struct TCP_Server_Info *server = tcon->ses->server;
13261324
struct smb_rqst rqst = { .rq_iov = rdata->iov,
13271325
.rq_nvec = 1,
13281326
.rq_iter = rdata->subreq.io_iter };
@@ -1420,7 +1418,7 @@ cifs_readv_callback(struct mid_q_entry *mid)
14201418
rdata->subreq.transferred += rdata->got_bytes;
14211419
trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_progress);
14221420
netfs_read_subreq_terminated(&rdata->subreq);
1423-
release_mid(mid);
1421+
release_mid(server, mid);
14241422
add_credits(server, &credits, 0);
14251423
trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, 0,
14261424
server->credits, server->in_flight,
@@ -1736,10 +1734,9 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
17361734
* workqueue completion task.
17371735
*/
17381736
static void
1739-
cifs_writev_callback(struct mid_q_entry *mid)
1737+
cifs_writev_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
17401738
{
17411739
struct cifs_io_subrequest *wdata = mid->callback_data;
1742-
struct TCP_Server_Info *server = wdata->server;
17431740
struct cifs_tcon *tcon = tlink_tcon(wdata->req->cfile->tlink);
17441741
WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf;
17451742
struct cifs_credits credits = {
@@ -1803,7 +1800,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
18031800
0, cifs_trace_rw_credits_write_response_clear);
18041801
wdata->credits.value = 0;
18051802
cifs_write_subrequest_terminated(wdata, result);
1806-
release_mid(mid);
1803+
release_mid(server, mid);
18071804
trace_smb3_rw_credits(credits.rreq_debug_id, credits.rreq_debug_index, 0,
18081805
server->credits, server->in_flight,
18091806
credits.value, cifs_trace_rw_credits_write_response_add);

fs/smb/client/cifstransport.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ alloc_mid(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
4343
return NULL;
4444
}
4545

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

5958
/*
6059
* 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)
119118

120119
rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
121120
if (rc) {
122-
release_mid(mid);
121+
release_mid(server, mid);
123122
return ERR_PTR(rc);
124123
}
125124

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

181180
/* BB special case reconnect tid and uid here? */
182-
return map_and_check_smb_error(mid, log_error);
181+
return map_and_check_smb_error(server, mid, log_error);
183182
}
184183

185184
struct mid_q_entry *
186-
cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored,
185+
cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server,
187186
struct smb_rqst *rqst)
188187
{
189188
int rc;
@@ -193,9 +192,9 @@ cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored,
193192
rc = allocate_mid(ses, hdr, &mid);
194193
if (rc)
195194
return ERR_PTR(rc);
196-
rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number);
195+
rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
197196
if (rc) {
198-
delete_mid(mid);
197+
delete_mid(server, mid);
199198
return ERR_PTR(rc);
200199
}
201200
return mid;

fs/smb/client/connect.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)
325325
cifs_dbg(FYI, "%s: moving mids to private list\n", __func__);
326326
spin_lock(&server->mid_queue_lock);
327327
list_for_each_entry_safe(mid, nmid, &server->pending_mid_q, qhead) {
328-
kref_get(&mid->refcount);
328+
smb_get_mid(mid);
329329
if (mid->mid_state == MID_REQUEST_SUBMITTED)
330330
mid->mid_state = MID_RETRY_NEEDED;
331331
list_move(&mid->qhead, &retry_list);
@@ -337,8 +337,8 @@ cifs_abort_connection(struct TCP_Server_Info *server)
337337
cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__);
338338
list_for_each_entry_safe(mid, nmid, &retry_list, qhead) {
339339
list_del_init(&mid->qhead);
340-
mid_execute_callback(mid);
341-
release_mid(mid);
340+
mid_execute_callback(server, mid);
341+
release_mid(server, mid);
342342
}
343343
}
344344

@@ -882,7 +882,7 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)
882882
*/
883883
spin_lock(&server->mid_queue_lock);
884884
list_for_each_entry_safe(mid, nmid, &server->pending_mid_q, qhead) {
885-
kref_get(&mid->refcount);
885+
smb_get_mid(mid);
886886
list_move(&mid->qhead, &dispose_list);
887887
mid->deleted_from_q = true;
888888
}
@@ -915,8 +915,8 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)
915915
list_del_init(&mid->qhead);
916916
mid->mid_rc = mid_rc;
917917
mid->mid_state = MID_RC;
918-
mid_execute_callback(mid);
919-
release_mid(mid);
918+
mid_execute_callback(server, mid);
919+
release_mid(server, mid);
920920
}
921921

922922
/*
@@ -948,12 +948,12 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)
948948
}
949949

950950
void
951-
dequeue_mid(struct mid_q_entry *mid, bool malformed)
951+
dequeue_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid, bool malformed)
952952
{
953953
#ifdef CONFIG_CIFS_STATS2
954954
mid->when_received = jiffies;
955955
#endif
956-
spin_lock(&mid->server->mid_queue_lock);
956+
spin_lock(&server->mid_queue_lock);
957957
if (!malformed)
958958
mid->mid_state = MID_RESPONSE_RECEIVED;
959959
else
@@ -963,12 +963,12 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed)
963963
* function has finished processing it is a bug.
964964
*/
965965
if (mid->deleted_from_q == true) {
966-
spin_unlock(&mid->server->mid_queue_lock);
966+
spin_unlock(&server->mid_queue_lock);
967967
pr_warn_once("trying to dequeue a deleted mid\n");
968968
} else {
969969
list_del_init(&mid->qhead);
970970
mid->deleted_from_q = true;
971-
spin_unlock(&mid->server->mid_queue_lock);
971+
spin_unlock(&server->mid_queue_lock);
972972
}
973973
}
974974

@@ -1004,7 +1004,7 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server,
10041004
else
10051005
server->smallbuf = NULL;
10061006
}
1007-
dequeue_mid(mid, malformed);
1007+
dequeue_mid(server, mid, malformed);
10081008
}
10091009

10101010
int
@@ -1101,7 +1101,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server)
11011101
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
11021102
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
11031103
cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid);
1104-
kref_get(&mid_entry->refcount);
1104+
smb_get_mid(mid_entry);
11051105
mid_entry->mid_state = MID_SHUTDOWN;
11061106
list_move(&mid_entry->qhead, &dispose_list);
11071107
mid_entry->deleted_from_q = true;
@@ -1113,8 +1113,8 @@ clean_demultiplex_info(struct TCP_Server_Info *server)
11131113
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
11141114
cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid);
11151115
list_del_init(&mid_entry->qhead);
1116-
mid_execute_callback(mid_entry);
1117-
release_mid(mid_entry);
1116+
mid_execute_callback(server, mid_entry);
1117+
release_mid(server, mid_entry);
11181118
}
11191119
/* 1/8th of sec is more than enough time for them to exit */
11201120
msleep(125);
@@ -1355,7 +1355,7 @@ cifs_demultiplex_thread(void *p)
13551355
if (length < 0) {
13561356
for (i = 0; i < num_mids; i++)
13571357
if (mids[i])
1358-
release_mid(mids[i]);
1358+
release_mid(server, mids[i]);
13591359
continue;
13601360
}
13611361

@@ -1388,9 +1388,9 @@ cifs_demultiplex_thread(void *p)
13881388
}
13891389

13901390
if (!mids[i]->multiRsp || mids[i]->multiEnd)
1391-
mid_execute_callback(mids[i]);
1391+
mid_execute_callback(server, mids[i]);
13921392

1393-
release_mid(mids[i]);
1393+
release_mid(server, mids[i]);
13941394
} else if (server->ops->is_oplock_break &&
13951395
server->ops->is_oplock_break(bufs[i],
13961396
server)) {

fs/smb/client/netmisc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ map_smb_to_linux_error(char *buf, bool logErr)
889889
}
890890

891891
int
892-
map_and_check_smb_error(struct mid_q_entry *mid, bool logErr)
892+
map_and_check_smb_error(struct TCP_Server_Info *server,
893+
struct mid_q_entry *mid, bool logErr)
893894
{
894895
int rc;
895896
struct smb_hdr *smb = (struct smb_hdr *)mid->resp_buf;
@@ -904,7 +905,7 @@ map_and_check_smb_error(struct mid_q_entry *mid, bool logErr)
904905
if (class == ERRSRV && code == ERRbaduid) {
905906
cifs_dbg(FYI, "Server returned 0x%x, reconnecting session...\n",
906907
code);
907-
cifs_signal_cifsd_for_reconnect(mid->server, false);
908+
cifs_signal_cifsd_for_reconnect(server, false);
908909
}
909910
}
910911

fs/smb/client/smb1ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
146146
if (compare_mid(mid->mid, buf) &&
147147
mid->mid_state == MID_REQUEST_SUBMITTED &&
148148
le16_to_cpu(mid->command) == buf->Command) {
149-
kref_get(&mid->refcount);
149+
smb_get_mid(mid);
150150
spin_unlock(&server->mid_queue_lock);
151151
return mid;
152152
}
@@ -448,7 +448,7 @@ cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,
448448
return true;
449449
/* All parts received or packet is malformed. */
450450
mid->multiEnd = true;
451-
dequeue_mid(mid, malformed);
451+
dequeue_mid(server, mid, malformed);
452452
return true;
453453
}
454454
if (!server->large_buf) {

0 commit comments

Comments
 (0)