1
+ // SPDX-License-Identifier: GPL-2.0
1
2
/*
2
3
* NVM Express device driver
3
4
* Copyright (c) 2011-2014, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
5
*/
14
6
15
7
#include <linux/blkdev.h>
@@ -151,11 +143,8 @@ int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)
151
143
}
152
144
EXPORT_SYMBOL_GPL (nvme_reset_ctrl_sync );
153
145
154
- static void nvme_delete_ctrl_work (struct work_struct * work )
146
+ static void nvme_do_delete_ctrl (struct nvme_ctrl * ctrl )
155
147
{
156
- struct nvme_ctrl * ctrl =
157
- container_of (work , struct nvme_ctrl , delete_work );
158
-
159
148
dev_info (ctrl -> device ,
160
149
"Removing ctrl: NQN \"%s\"\n" , ctrl -> opts -> subsysnqn );
161
150
@@ -167,6 +156,14 @@ static void nvme_delete_ctrl_work(struct work_struct *work)
167
156
nvme_put_ctrl (ctrl );
168
157
}
169
158
159
+ static void nvme_delete_ctrl_work (struct work_struct * work )
160
+ {
161
+ struct nvme_ctrl * ctrl =
162
+ container_of (work , struct nvme_ctrl , delete_work );
163
+
164
+ nvme_do_delete_ctrl (ctrl );
165
+ }
166
+
170
167
int nvme_delete_ctrl (struct nvme_ctrl * ctrl )
171
168
{
172
169
if (!nvme_change_ctrl_state (ctrl , NVME_CTRL_DELETING ))
@@ -177,7 +174,7 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
177
174
}
178
175
EXPORT_SYMBOL_GPL (nvme_delete_ctrl );
179
176
180
- int nvme_delete_ctrl_sync (struct nvme_ctrl * ctrl )
177
+ static int nvme_delete_ctrl_sync (struct nvme_ctrl * ctrl )
181
178
{
182
179
int ret = 0 ;
183
180
@@ -186,13 +183,13 @@ int nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
186
183
* can free the controller.
187
184
*/
188
185
nvme_get_ctrl (ctrl );
189
- ret = nvme_delete_ctrl (ctrl );
186
+ if (!nvme_change_ctrl_state (ctrl , NVME_CTRL_DELETING ))
187
+ ret = - EBUSY ;
190
188
if (!ret )
191
- flush_work ( & ctrl -> delete_work );
189
+ nvme_do_delete_ctrl ( ctrl );
192
190
nvme_put_ctrl (ctrl );
193
191
return ret ;
194
192
}
195
- EXPORT_SYMBOL_GPL (nvme_delete_ctrl_sync );
196
193
197
194
static inline bool nvme_ns_has_pi (struct nvme_ns * ns )
198
195
{
@@ -2328,6 +2325,9 @@ static struct attribute *nvme_subsys_attrs[] = {
2328
2325
& subsys_attr_serial .attr ,
2329
2326
& subsys_attr_firmware_rev .attr ,
2330
2327
& subsys_attr_subsysnqn .attr ,
2328
+ #ifdef CONFIG_NVME_MULTIPATH
2329
+ & subsys_attr_iopolicy .attr ,
2330
+ #endif
2331
2331
NULL ,
2332
2332
};
2333
2333
@@ -2380,6 +2380,9 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
2380
2380
memcpy (subsys -> firmware_rev , id -> fr , sizeof (subsys -> firmware_rev ));
2381
2381
subsys -> vendor_id = le16_to_cpu (id -> vid );
2382
2382
subsys -> cmic = id -> cmic ;
2383
+ #ifdef CONFIG_NVME_MULTIPATH
2384
+ subsys -> iopolicy = NVME_IOPOLICY_NUMA ;
2385
+ #endif
2383
2386
2384
2387
subsys -> dev .class = nvme_subsys_class ;
2385
2388
subsys -> dev .release = nvme_release_subsystem ;
@@ -3211,21 +3214,23 @@ static int nvme_setup_streams_ns(struct nvme_ctrl *ctrl, struct nvme_ns *ns)
3211
3214
return 0 ;
3212
3215
}
3213
3216
3214
- static void nvme_alloc_ns (struct nvme_ctrl * ctrl , unsigned nsid )
3217
+ static int nvme_alloc_ns (struct nvme_ctrl * ctrl , unsigned nsid )
3215
3218
{
3216
3219
struct nvme_ns * ns ;
3217
3220
struct gendisk * disk ;
3218
3221
struct nvme_id_ns * id ;
3219
3222
char disk_name [DISK_NAME_LEN ];
3220
- int node = ctrl -> numa_node , flags = GENHD_FL_EXT_DEVT ;
3223
+ int node = ctrl -> numa_node , flags = GENHD_FL_EXT_DEVT , ret ;
3221
3224
3222
3225
ns = kzalloc_node (sizeof (* ns ), GFP_KERNEL , node );
3223
3226
if (!ns )
3224
- return ;
3227
+ return - ENOMEM ;
3225
3228
3226
3229
ns -> queue = blk_mq_init_queue (ctrl -> tagset );
3227
- if (IS_ERR (ns -> queue ))
3230
+ if (IS_ERR (ns -> queue )) {
3231
+ ret = PTR_ERR (ns -> queue );
3228
3232
goto out_free_ns ;
3233
+ }
3229
3234
3230
3235
blk_queue_flag_set (QUEUE_FLAG_NONROT , ns -> queue );
3231
3236
if (ctrl -> ops -> flags & NVME_F_PCI_P2PDMA )
@@ -3241,20 +3246,27 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3241
3246
nvme_set_queue_limits (ctrl , ns -> queue );
3242
3247
3243
3248
id = nvme_identify_ns (ctrl , nsid );
3244
- if (!id )
3249
+ if (!id ) {
3250
+ ret = - EIO ;
3245
3251
goto out_free_queue ;
3252
+ }
3246
3253
3247
- if (id -> ncap == 0 )
3254
+ if (id -> ncap == 0 ) {
3255
+ ret = - EINVAL ;
3248
3256
goto out_free_id ;
3257
+ }
3249
3258
3250
- if (nvme_init_ns_head (ns , nsid , id ))
3259
+ ret = nvme_init_ns_head (ns , nsid , id );
3260
+ if (ret )
3251
3261
goto out_free_id ;
3252
3262
nvme_setup_streams_ns (ctrl , ns );
3253
3263
nvme_set_disk_name (disk_name , ns , ctrl , & flags );
3254
3264
3255
3265
disk = alloc_disk_node (0 , node );
3256
- if (!disk )
3266
+ if (!disk ) {
3267
+ ret = - ENOMEM ;
3257
3268
goto out_unlink_ns ;
3269
+ }
3258
3270
3259
3271
disk -> fops = & nvme_fops ;
3260
3272
disk -> private_data = ns ;
@@ -3266,7 +3278,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3266
3278
__nvme_revalidate_disk (disk , id );
3267
3279
3268
3280
if ((ctrl -> quirks & NVME_QUIRK_LIGHTNVM ) && id -> vs [0 ] == 0x1 ) {
3269
- if (nvme_nvm_register (ns , disk_name , node )) {
3281
+ ret = nvme_nvm_register (ns , disk_name , node );
3282
+ if (ret ) {
3270
3283
dev_warn (ctrl -> device , "LightNVM init failure\n" );
3271
3284
goto out_put_disk ;
3272
3285
}
@@ -3284,7 +3297,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3284
3297
nvme_fault_inject_init (ns );
3285
3298
kfree (id );
3286
3299
3287
- return ;
3300
+ return 0 ;
3288
3301
out_put_disk :
3289
3302
put_disk (ns -> disk );
3290
3303
out_unlink_ns :
@@ -3297,6 +3310,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
3297
3310
blk_cleanup_queue (ns -> queue );
3298
3311
out_free_ns :
3299
3312
kfree (ns );
3313
+ return ret ;
3300
3314
}
3301
3315
3302
3316
static void nvme_ns_remove (struct nvme_ns * ns )
0 commit comments