@@ -51,6 +51,7 @@ static struct oplock_info *alloc_opinfo(struct ksmbd_work *work,
51
51
init_waitqueue_head (& opinfo -> oplock_brk );
52
52
atomic_set (& opinfo -> refcount , 1 );
53
53
atomic_set (& opinfo -> breaking_cnt , 0 );
54
+ atomic_inc (& opinfo -> conn -> refcnt );
54
55
55
56
return opinfo ;
56
57
}
@@ -124,6 +125,8 @@ static void free_opinfo(struct oplock_info *opinfo)
124
125
{
125
126
if (opinfo -> is_lease )
126
127
free_lease (opinfo );
128
+ if (opinfo -> conn && atomic_dec_and_test (& opinfo -> conn -> refcnt ))
129
+ kfree (opinfo -> conn );
127
130
kfree (opinfo );
128
131
}
129
132
@@ -163,9 +166,7 @@ static struct oplock_info *opinfo_get_list(struct ksmbd_inode *ci)
163
166
!atomic_inc_not_zero (& opinfo -> refcount ))
164
167
opinfo = NULL ;
165
168
else {
166
- atomic_inc (& opinfo -> conn -> r_count );
167
169
if (ksmbd_conn_releasing (opinfo -> conn )) {
168
- atomic_dec (& opinfo -> conn -> r_count );
169
170
atomic_dec (& opinfo -> refcount );
170
171
opinfo = NULL ;
171
172
}
@@ -177,26 +178,11 @@ static struct oplock_info *opinfo_get_list(struct ksmbd_inode *ci)
177
178
return opinfo ;
178
179
}
179
180
180
- static void opinfo_conn_put (struct oplock_info * opinfo )
181
+ void opinfo_put (struct oplock_info * opinfo )
181
182
{
182
- struct ksmbd_conn * conn ;
183
-
184
183
if (!opinfo )
185
184
return ;
186
185
187
- conn = opinfo -> conn ;
188
- /*
189
- * Checking waitqueue to dropping pending requests on
190
- * disconnection. waitqueue_active is safe because it
191
- * uses atomic operation for condition.
192
- */
193
- if (!atomic_dec_return (& conn -> r_count ) && waitqueue_active (& conn -> r_count_q ))
194
- wake_up (& conn -> r_count_q );
195
- opinfo_put (opinfo );
196
- }
197
-
198
- void opinfo_put (struct oplock_info * opinfo )
199
- {
200
186
if (!atomic_dec_and_test (& opinfo -> refcount ))
201
187
return ;
202
188
@@ -1127,14 +1113,11 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
1127
1113
if (!atomic_inc_not_zero (& opinfo -> refcount ))
1128
1114
continue ;
1129
1115
1130
- atomic_inc (& opinfo -> conn -> r_count );
1131
- if (ksmbd_conn_releasing (opinfo -> conn )) {
1132
- atomic_dec (& opinfo -> conn -> r_count );
1116
+ if (ksmbd_conn_releasing (opinfo -> conn ))
1133
1117
continue ;
1134
- }
1135
1118
1136
1119
oplock_break (opinfo , SMB2_OPLOCK_LEVEL_NONE );
1137
- opinfo_conn_put (opinfo );
1120
+ opinfo_put (opinfo );
1138
1121
}
1139
1122
}
1140
1123
up_read (& p_ci -> m_lock );
@@ -1167,13 +1150,10 @@ void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
1167
1150
if (!atomic_inc_not_zero (& opinfo -> refcount ))
1168
1151
continue ;
1169
1152
1170
- atomic_inc (& opinfo -> conn -> r_count );
1171
- if (ksmbd_conn_releasing (opinfo -> conn )) {
1172
- atomic_dec (& opinfo -> conn -> r_count );
1153
+ if (ksmbd_conn_releasing (opinfo -> conn ))
1173
1154
continue ;
1174
- }
1175
1155
oplock_break (opinfo , SMB2_OPLOCK_LEVEL_NONE );
1176
- opinfo_conn_put (opinfo );
1156
+ opinfo_put (opinfo );
1177
1157
}
1178
1158
}
1179
1159
up_read (& p_ci -> m_lock );
@@ -1252,7 +1232,7 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
1252
1232
prev_opinfo = opinfo_get_list (ci );
1253
1233
if (!prev_opinfo ||
1254
1234
(prev_opinfo -> level == SMB2_OPLOCK_LEVEL_NONE && lctx )) {
1255
- opinfo_conn_put (prev_opinfo );
1235
+ opinfo_put (prev_opinfo );
1256
1236
goto set_lev ;
1257
1237
}
1258
1238
prev_op_has_lease = prev_opinfo -> is_lease ;
@@ -1262,19 +1242,19 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
1262
1242
if (share_ret < 0 &&
1263
1243
prev_opinfo -> level == SMB2_OPLOCK_LEVEL_EXCLUSIVE ) {
1264
1244
err = share_ret ;
1265
- opinfo_conn_put (prev_opinfo );
1245
+ opinfo_put (prev_opinfo );
1266
1246
goto err_out ;
1267
1247
}
1268
1248
1269
1249
if (prev_opinfo -> level != SMB2_OPLOCK_LEVEL_BATCH &&
1270
1250
prev_opinfo -> level != SMB2_OPLOCK_LEVEL_EXCLUSIVE ) {
1271
- opinfo_conn_put (prev_opinfo );
1251
+ opinfo_put (prev_opinfo );
1272
1252
goto op_break_not_needed ;
1273
1253
}
1274
1254
1275
1255
list_add (& work -> interim_entry , & prev_opinfo -> interim_list );
1276
1256
err = oplock_break (prev_opinfo , SMB2_OPLOCK_LEVEL_II );
1277
- opinfo_conn_put (prev_opinfo );
1257
+ opinfo_put (prev_opinfo );
1278
1258
if (err == - ENOENT )
1279
1259
goto set_lev ;
1280
1260
/* Check all oplock was freed by close */
@@ -1337,14 +1317,14 @@ static void smb_break_all_write_oplock(struct ksmbd_work *work,
1337
1317
return ;
1338
1318
if (brk_opinfo -> level != SMB2_OPLOCK_LEVEL_BATCH &&
1339
1319
brk_opinfo -> level != SMB2_OPLOCK_LEVEL_EXCLUSIVE ) {
1340
- opinfo_conn_put (brk_opinfo );
1320
+ opinfo_put (brk_opinfo );
1341
1321
return ;
1342
1322
}
1343
1323
1344
1324
brk_opinfo -> open_trunc = is_trunc ;
1345
1325
list_add (& work -> interim_entry , & brk_opinfo -> interim_list );
1346
1326
oplock_break (brk_opinfo , SMB2_OPLOCK_LEVEL_II );
1347
- opinfo_conn_put (brk_opinfo );
1327
+ opinfo_put (brk_opinfo );
1348
1328
}
1349
1329
1350
1330
/**
@@ -1376,11 +1356,8 @@ void smb_break_all_levII_oplock(struct ksmbd_work *work, struct ksmbd_file *fp,
1376
1356
if (!atomic_inc_not_zero (& brk_op -> refcount ))
1377
1357
continue ;
1378
1358
1379
- atomic_inc (& brk_op -> conn -> r_count );
1380
- if (ksmbd_conn_releasing (brk_op -> conn )) {
1381
- atomic_dec (& brk_op -> conn -> r_count );
1359
+ if (ksmbd_conn_releasing (brk_op -> conn ))
1382
1360
continue ;
1383
- }
1384
1361
1385
1362
rcu_read_unlock ();
1386
1363
if (brk_op -> is_lease && (brk_op -> o_lease -> state &
@@ -1411,7 +1388,7 @@ void smb_break_all_levII_oplock(struct ksmbd_work *work, struct ksmbd_file *fp,
1411
1388
brk_op -> open_trunc = is_trunc ;
1412
1389
oplock_break (brk_op , SMB2_OPLOCK_LEVEL_NONE );
1413
1390
next :
1414
- opinfo_conn_put (brk_op );
1391
+ opinfo_put (brk_op );
1415
1392
rcu_read_lock ();
1416
1393
}
1417
1394
rcu_read_unlock ();
0 commit comments