Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause
2 : * Copyright (C) 2017 Intel Corporation.
3 : * All rights reserved.
4 : */
5 :
6 : /*
7 : * This driver reads a GPT partition table from a bdev and exposes a virtual block device for
8 : * each partition.
9 : */
10 :
11 : #define REGISTER_GUID_DEPRECATION
12 : #include "gpt.h"
13 :
14 : #include "spdk/endian.h"
15 : #include "spdk/env.h"
16 : #include "spdk/thread.h"
17 : #include "spdk/rpc.h"
18 : #include "spdk/string.h"
19 : #include "spdk/util.h"
20 :
21 : #include "spdk/bdev_module.h"
22 : #include "spdk/log.h"
23 :
24 : static int vbdev_gpt_init(void);
25 : static void vbdev_gpt_examine(struct spdk_bdev *bdev);
26 : static int vbdev_gpt_get_ctx_size(void);
27 :
28 : static struct spdk_bdev_module gpt_if = {
29 : .name = "gpt",
30 : .module_init = vbdev_gpt_init,
31 : .get_ctx_size = vbdev_gpt_get_ctx_size,
32 : .examine_disk = vbdev_gpt_examine,
33 :
34 : };
35 0 : SPDK_BDEV_MODULE_REGISTER(gpt, &gpt_if)
36 :
37 : /* Base block device gpt context */
38 : struct gpt_base {
39 : struct spdk_gpt gpt;
40 : struct spdk_bdev_part_base *part_base;
41 : SPDK_BDEV_PART_TAILQ parts;
42 :
43 : /* This channel is only used for reading the partition table. */
44 : struct spdk_io_channel *ch;
45 : };
46 :
47 : /* Context for each gpt virtual bdev */
48 : struct gpt_disk {
49 : struct spdk_bdev_part part;
50 : uint32_t partition_index;
51 : };
52 :
53 : struct gpt_channel {
54 : struct spdk_bdev_part_channel part_ch;
55 : };
56 :
57 : struct gpt_io {
58 : struct spdk_io_channel *ch;
59 : struct spdk_bdev_io *bdev_io;
60 :
61 : /* for bdev_io_wait */
62 : struct spdk_bdev_io_wait_entry bdev_io_wait;
63 : };
64 :
65 : static void
66 0 : gpt_base_free(void *ctx)
67 : {
68 0 : struct gpt_base *gpt_base = ctx;
69 :
70 0 : spdk_free(gpt_base->gpt.buf);
71 0 : free(gpt_base);
72 0 : }
73 :
74 : static void
75 0 : gpt_base_bdev_hotremove_cb(void *_part_base)
76 : {
77 0 : struct spdk_bdev_part_base *part_base = _part_base;
78 0 : struct gpt_base *gpt_base = spdk_bdev_part_base_get_ctx(part_base);
79 :
80 0 : spdk_bdev_part_base_hotremove(part_base, &gpt_base->parts);
81 0 : }
82 :
83 : static int vbdev_gpt_destruct(void *ctx);
84 : static void vbdev_gpt_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_io);
85 : static int vbdev_gpt_dump_info_json(void *ctx, struct spdk_json_write_ctx *w);
86 : static int vbdev_gpt_get_memory_domains(void *ctx, struct spdk_memory_domain **domains,
87 : int array_size);
88 :
89 : static struct spdk_bdev_fn_table vbdev_gpt_fn_table = {
90 : .destruct = vbdev_gpt_destruct,
91 : .submit_request = vbdev_gpt_submit_request,
92 : .dump_info_json = vbdev_gpt_dump_info_json,
93 : .get_memory_domains = vbdev_gpt_get_memory_domains,
94 : };
95 :
96 : static struct gpt_base *
97 0 : gpt_base_bdev_init(struct spdk_bdev *bdev)
98 : {
99 : struct gpt_base *gpt_base;
100 : struct spdk_gpt *gpt;
101 : int rc;
102 :
103 0 : gpt_base = calloc(1, sizeof(*gpt_base));
104 0 : if (!gpt_base) {
105 0 : SPDK_ERRLOG("Cannot alloc memory for gpt_base pointer\n");
106 0 : return NULL;
107 : }
108 :
109 0 : TAILQ_INIT(&gpt_base->parts);
110 0 : rc = spdk_bdev_part_base_construct_ext(spdk_bdev_get_name(bdev),
111 : gpt_base_bdev_hotremove_cb,
112 : &gpt_if, &vbdev_gpt_fn_table,
113 0 : &gpt_base->parts, gpt_base_free, gpt_base,
114 : sizeof(struct gpt_channel), NULL, NULL, &gpt_base->part_base);
115 0 : if (rc != 0) {
116 0 : free(gpt_base);
117 0 : SPDK_ERRLOG("cannot construct gpt_base");
118 0 : return NULL;
119 : }
120 :
121 0 : gpt = &gpt_base->gpt;
122 0 : gpt->parse_phase = SPDK_GPT_PARSE_PHASE_PRIMARY;
123 0 : gpt->buf_size = spdk_max(SPDK_GPT_BUFFER_SIZE, bdev->blocklen);
124 0 : gpt->buf = spdk_zmalloc(gpt->buf_size, spdk_bdev_get_buf_align(bdev), NULL,
125 : SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
126 0 : if (!gpt->buf) {
127 0 : SPDK_ERRLOG("Cannot alloc buf\n");
128 0 : spdk_bdev_part_base_free(gpt_base->part_base);
129 0 : return NULL;
130 : }
131 :
132 0 : gpt->sector_size = bdev->blocklen;
133 0 : gpt->total_sectors = bdev->blockcnt;
134 0 : gpt->lba_start = 0;
135 0 : gpt->lba_end = gpt->total_sectors - 1;
136 :
137 0 : return gpt_base;
138 : }
139 :
140 : static int
141 0 : vbdev_gpt_destruct(void *ctx)
142 : {
143 0 : struct gpt_disk *gpt_disk = ctx;
144 :
145 0 : return spdk_bdev_part_free(&gpt_disk->part);
146 : }
147 :
148 : static void _vbdev_gpt_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_io);
149 :
150 : static void
151 0 : vbdev_gpt_resubmit_request(void *arg)
152 : {
153 0 : struct gpt_io *io = (struct gpt_io *)arg;
154 :
155 0 : _vbdev_gpt_submit_request(io->ch, io->bdev_io);
156 0 : }
157 :
158 : static void
159 0 : vbdev_gpt_queue_io(struct gpt_io *io)
160 : {
161 0 : struct gpt_channel *ch = spdk_io_channel_get_ctx(io->ch);
162 : int rc;
163 :
164 0 : io->bdev_io_wait.bdev = io->bdev_io->bdev;
165 0 : io->bdev_io_wait.cb_fn = vbdev_gpt_resubmit_request;
166 0 : io->bdev_io_wait.cb_arg = io;
167 :
168 0 : rc = spdk_bdev_queue_io_wait(io->bdev_io->bdev,
169 : ch->part_ch.base_ch, &io->bdev_io_wait);
170 0 : if (rc != 0) {
171 0 : SPDK_ERRLOG("Queue io failed in vbdev_gpt_queue_io, rc=%d.\n", rc);
172 0 : spdk_bdev_io_complete(io->bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
173 : }
174 0 : }
175 :
176 : static void
177 0 : vbdev_gpt_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, bool success)
178 : {
179 0 : if (!success) {
180 0 : spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
181 0 : return;
182 : }
183 :
184 0 : _vbdev_gpt_submit_request(ch, bdev_io);
185 : }
186 :
187 : static void
188 0 : _vbdev_gpt_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_io)
189 : {
190 0 : struct gpt_channel *ch = spdk_io_channel_get_ctx(_ch);
191 0 : struct gpt_io *io = (struct gpt_io *)bdev_io->driver_ctx;
192 : int rc;
193 :
194 0 : rc = spdk_bdev_part_submit_request(&ch->part_ch, bdev_io);
195 0 : if (rc) {
196 0 : if (rc == -ENOMEM) {
197 0 : SPDK_DEBUGLOG(vbdev_gpt, "gpt: no memory, queue io\n");
198 0 : io->ch = _ch;
199 0 : io->bdev_io = bdev_io;
200 0 : vbdev_gpt_queue_io(io);
201 : } else {
202 0 : SPDK_ERRLOG("gpt: error on bdev_io submission, rc=%d.\n", rc);
203 0 : spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
204 : }
205 : }
206 0 : }
207 :
208 : static void
209 0 : vbdev_gpt_submit_request(struct spdk_io_channel *_ch, struct spdk_bdev_io *bdev_io)
210 : {
211 0 : switch (bdev_io->type) {
212 0 : case SPDK_BDEV_IO_TYPE_READ:
213 0 : spdk_bdev_io_get_buf(bdev_io, vbdev_gpt_get_buf_cb,
214 0 : bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen);
215 0 : break;
216 0 : default:
217 0 : _vbdev_gpt_submit_request(_ch, bdev_io);
218 0 : break;
219 : }
220 0 : }
221 :
222 : static void
223 0 : gpt_guid_to_uuid(const struct spdk_gpt_guid *guid, struct spdk_uuid *uuid)
224 : {
225 : #pragma pack(push, 1)
226 : struct tmp_uuid {
227 : uint32_t b0;
228 : uint16_t b4;
229 : uint16_t b6;
230 : uint16_t b8;
231 : uint16_t b10;
232 : uint32_t b12;
233 0 : } *ret = (struct tmp_uuid *)uuid;
234 : #pragma pack(pop)
235 : SPDK_STATIC_ASSERT(sizeof(*ret) == sizeof(*uuid), "wrong size");
236 :
237 0 : ret->b0 = from_be32(&guid->raw[0]);
238 0 : ret->b4 = from_be16(&guid->raw[4]);
239 0 : ret->b6 = from_be16(&guid->raw[6]);
240 0 : ret->b8 = from_le16(&guid->raw[8]);
241 0 : ret->b10 = from_le16(&guid->raw[10]);
242 0 : ret->b12 = from_le32(&guid->raw[12]);
243 0 : }
244 :
245 : static void
246 0 : write_guid(struct spdk_json_write_ctx *w, const struct spdk_gpt_guid *guid)
247 : {
248 0 : spdk_json_write_string_fmt(w, "%08x-%04x-%04x-%04x-%04x%08x",
249 0 : from_le32(&guid->raw[0]),
250 0 : from_le16(&guid->raw[4]),
251 0 : from_le16(&guid->raw[6]),
252 0 : from_be16(&guid->raw[8]),
253 0 : from_be16(&guid->raw[10]),
254 0 : from_be32(&guid->raw[12]));
255 0 : }
256 :
257 : static void
258 0 : write_string_utf16le(struct spdk_json_write_ctx *w, const uint16_t *str, size_t max_len)
259 : {
260 : size_t len;
261 : const uint16_t *p;
262 :
263 0 : for (len = 0, p = str; len < max_len && *p; p++) {
264 0 : len++;
265 : }
266 :
267 0 : spdk_json_write_string_utf16le_raw(w, str, len);
268 0 : }
269 :
270 : static int
271 0 : vbdev_gpt_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
272 : {
273 0 : struct gpt_disk *gpt_disk = SPDK_CONTAINEROF(ctx, struct gpt_disk, part);
274 0 : struct spdk_bdev_part_base *base_bdev = spdk_bdev_part_get_base(&gpt_disk->part);
275 0 : struct gpt_base *gpt_base = spdk_bdev_part_base_get_ctx(base_bdev);
276 0 : struct spdk_bdev *part_base_bdev = spdk_bdev_part_base_get_bdev(base_bdev);
277 0 : struct spdk_gpt *gpt = &gpt_base->gpt;
278 0 : struct spdk_gpt_partition_entry *gpt_entry = &gpt->partitions[gpt_disk->partition_index];
279 0 : uint64_t offset_blocks = spdk_bdev_part_get_offset_blocks(&gpt_disk->part);
280 :
281 0 : spdk_json_write_named_object_begin(w, "gpt");
282 :
283 0 : spdk_json_write_named_string(w, "base_bdev", spdk_bdev_get_name(part_base_bdev));
284 :
285 0 : spdk_json_write_named_uint64(w, "offset_blocks", offset_blocks);
286 :
287 0 : spdk_json_write_name(w, "partition_type_guid");
288 0 : write_guid(w, &gpt_entry->part_type_guid);
289 :
290 0 : spdk_json_write_name(w, "unique_partition_guid");
291 0 : write_guid(w, &gpt_entry->unique_partition_guid);
292 :
293 0 : spdk_json_write_name(w, "partition_name");
294 0 : write_string_utf16le(w, gpt_entry->partition_name, SPDK_COUNTOF(gpt_entry->partition_name));
295 :
296 0 : spdk_json_write_object_end(w);
297 :
298 0 : return 0;
299 : }
300 :
301 : static int
302 0 : vbdev_gpt_get_memory_domains(void *ctx, struct spdk_memory_domain **domains, int array_size)
303 : {
304 0 : struct gpt_disk *gpt_disk = SPDK_CONTAINEROF(ctx, struct gpt_disk, part);
305 0 : struct spdk_bdev_part_base *part_base = spdk_bdev_part_get_base(&gpt_disk->part);
306 0 : struct spdk_bdev *part_base_bdev = spdk_bdev_part_base_get_bdev(part_base);
307 :
308 0 : if (part_base_bdev->dif_check_flags & SPDK_DIF_FLAGS_REFTAG_CHECK) {
309 : /* bdev_part remaps reftag and touches metadata buffer, that means it can't support memory domains
310 : * if dif is enabled */
311 0 : return 0;
312 : }
313 :
314 0 : return spdk_bdev_get_memory_domains(part_base_bdev, domains, array_size);
315 : }
316 :
317 : static int
318 0 : vbdev_gpt_create_bdevs(struct gpt_base *gpt_base)
319 : {
320 : uint32_t num_partition_entries;
321 : uint64_t i, head_lba_start, head_lba_end;
322 : uint32_t num_partitions;
323 : struct spdk_gpt_partition_entry *p;
324 : struct gpt_disk *d;
325 : struct spdk_gpt *gpt;
326 : char *name;
327 : struct spdk_bdev *base_bdev;
328 : int rc;
329 :
330 0 : gpt = &gpt_base->gpt;
331 0 : num_partition_entries = from_le32(&gpt->header->num_partition_entries);
332 0 : head_lba_start = from_le64(&gpt->header->first_usable_lba);
333 0 : head_lba_end = from_le64(&gpt->header->last_usable_lba);
334 0 : num_partitions = 0;
335 :
336 0 : for (i = 0; i < num_partition_entries; i++) {
337 0 : p = &gpt->partitions[i];
338 0 : uint64_t lba_start = from_le64(&p->starting_lba);
339 0 : uint64_t lba_end = from_le64(&p->ending_lba);
340 0 : uint64_t partition_size = lba_end - lba_start + 1;
341 0 : struct spdk_bdev_part_construct_opts opts;
342 :
343 0 : if (lba_start == 0) {
344 0 : continue;
345 : }
346 :
347 0 : if (SPDK_GPT_GUID_EQUAL(&gpt->partitions[i].part_type_guid,
348 : &SPDK_GPT_PART_TYPE_GUID_OLD)) {
349 : /* GitHub issue #2801 - we continue to report these partitions with
350 : * off-by-one sizing error to ensure we don't break layouts based
351 : * on that smaller size. */
352 0 : partition_size -= 1;
353 0 : } else if (!SPDK_GPT_GUID_EQUAL(&gpt->partitions[i].part_type_guid,
354 : &SPDK_GPT_PART_TYPE_GUID)) {
355 : /* Partition type isn't TYPE_GUID or TYPE_GUID_OLD, so this isn't
356 : * an SPDK partition. Continue to the next partition.
357 : */
358 0 : continue;
359 : }
360 :
361 0 : if (lba_start < head_lba_start || lba_end > head_lba_end) {
362 0 : continue;
363 : }
364 :
365 0 : d = calloc(1, sizeof(*d));
366 0 : if (!d) {
367 0 : SPDK_ERRLOG("Memory allocation failure\n");
368 0 : return -1;
369 : }
370 :
371 : /* index start at 1 instead of 0 to match the existing style */
372 0 : base_bdev = spdk_bdev_part_base_get_bdev(gpt_base->part_base);
373 0 : name = spdk_sprintf_alloc("%sp%" PRIu64, spdk_bdev_get_name(base_bdev), i + 1);
374 0 : if (!name) {
375 0 : SPDK_ERRLOG("name allocation failure\n");
376 0 : free(d);
377 0 : return -1;
378 : }
379 :
380 0 : spdk_bdev_part_construct_opts_init(&opts, sizeof(opts));
381 0 : gpt_guid_to_uuid(&p->unique_partition_guid, &opts.uuid);
382 0 : rc = spdk_bdev_part_construct_ext(&d->part, gpt_base->part_base, name, lba_start,
383 : partition_size, "GPT Disk", &opts);
384 0 : free(name);
385 0 : if (rc) {
386 0 : SPDK_ERRLOG("could not construct bdev part\n");
387 : /* spdk_bdev_part_construct will free name on failure */
388 0 : free(d);
389 0 : return -1;
390 : }
391 0 : num_partitions++;
392 0 : d->partition_index = i;
393 : }
394 :
395 0 : return num_partitions;
396 : }
397 :
398 : static void
399 0 : gpt_read_secondary_table_complete(struct spdk_bdev_io *bdev_io, bool success, void *arg)
400 : {
401 0 : struct gpt_base *gpt_base = (struct gpt_base *)arg;
402 0 : struct spdk_bdev *bdev = spdk_bdev_part_base_get_bdev(gpt_base->part_base);
403 0 : int rc, num_partitions = 0;
404 :
405 0 : spdk_bdev_free_io(bdev_io);
406 0 : spdk_put_io_channel(gpt_base->ch);
407 0 : gpt_base->ch = NULL;
408 :
409 0 : if (!success) {
410 0 : SPDK_ERRLOG("Gpt: bdev=%s io error\n", spdk_bdev_get_name(bdev));
411 0 : goto end;
412 : }
413 :
414 0 : rc = gpt_parse_partition_table(&gpt_base->gpt);
415 0 : if (rc) {
416 0 : SPDK_DEBUGLOG(vbdev_gpt, "Failed to parse secondary partition table\n");
417 0 : goto end;
418 : }
419 :
420 0 : SPDK_WARNLOG("Gpt: bdev=%s primary partition table broken, use the secondary\n",
421 : spdk_bdev_get_name(bdev));
422 :
423 0 : num_partitions = vbdev_gpt_create_bdevs(gpt_base);
424 0 : if (num_partitions < 0) {
425 0 : SPDK_DEBUGLOG(vbdev_gpt, "Failed to split dev=%s by gpt table\n",
426 : spdk_bdev_get_name(bdev));
427 : }
428 :
429 0 : end:
430 0 : spdk_bdev_module_examine_done(&gpt_if);
431 0 : if (num_partitions <= 0) {
432 : /* If no gpt_disk instances were created, free the base context */
433 0 : spdk_bdev_part_base_free(gpt_base->part_base);
434 : }
435 0 : }
436 :
437 : static int
438 0 : vbdev_gpt_read_secondary_table(struct gpt_base *gpt_base)
439 : {
440 : struct spdk_gpt *gpt;
441 : struct spdk_bdev_desc *part_base_desc;
442 : uint64_t secondary_offset;
443 :
444 0 : gpt = &gpt_base->gpt;
445 0 : gpt->parse_phase = SPDK_GPT_PARSE_PHASE_SECONDARY;
446 0 : gpt->header = NULL;
447 0 : gpt->partitions = NULL;
448 :
449 0 : part_base_desc = spdk_bdev_part_base_get_desc(gpt_base->part_base);
450 :
451 0 : secondary_offset = gpt->total_sectors * gpt->sector_size - gpt->buf_size;
452 0 : return spdk_bdev_read(part_base_desc, gpt_base->ch, gpt_base->gpt.buf, secondary_offset,
453 : gpt_base->gpt.buf_size, gpt_read_secondary_table_complete,
454 : gpt_base);
455 : }
456 :
457 : static void
458 0 : gpt_bdev_complete(struct spdk_bdev_io *bdev_io, bool success, void *arg)
459 : {
460 0 : struct gpt_base *gpt_base = (struct gpt_base *)arg;
461 0 : struct spdk_bdev *bdev = spdk_bdev_part_base_get_bdev(gpt_base->part_base);
462 0 : int rc, num_partitions = 0;
463 :
464 0 : spdk_bdev_free_io(bdev_io);
465 :
466 0 : if (!success) {
467 0 : SPDK_ERRLOG("Gpt: bdev=%s io error\n", spdk_bdev_get_name(bdev));
468 0 : goto end;
469 : }
470 :
471 0 : rc = gpt_parse_mbr(&gpt_base->gpt);
472 0 : if (rc) {
473 0 : SPDK_DEBUGLOG(vbdev_gpt, "Failed to parse mbr\n");
474 0 : goto end;
475 : }
476 :
477 0 : rc = gpt_parse_partition_table(&gpt_base->gpt);
478 0 : if (rc) {
479 0 : SPDK_DEBUGLOG(vbdev_gpt, "Failed to parse primary partition table\n");
480 0 : rc = vbdev_gpt_read_secondary_table(gpt_base);
481 0 : if (rc) {
482 0 : SPDK_ERRLOG("Failed to read secondary table\n");
483 0 : goto end;
484 : }
485 0 : return;
486 : }
487 :
488 0 : num_partitions = vbdev_gpt_create_bdevs(gpt_base);
489 0 : if (num_partitions < 0) {
490 0 : SPDK_DEBUGLOG(vbdev_gpt, "Failed to split dev=%s by gpt table\n",
491 : spdk_bdev_get_name(bdev));
492 : }
493 :
494 0 : end:
495 0 : spdk_put_io_channel(gpt_base->ch);
496 0 : gpt_base->ch = NULL;
497 : /*
498 : * Notify the generic bdev layer that the actions related to the original examine
499 : * callback are now completed.
500 : */
501 0 : spdk_bdev_module_examine_done(&gpt_if);
502 :
503 : /*
504 : * vbdev_gpt_create_bdevs returns the number of bdevs created upon success.
505 : * We can branch on this value.
506 : */
507 0 : if (num_partitions <= 0) {
508 : /* If no gpt_disk instances were created, free the base context */
509 0 : spdk_bdev_part_base_free(gpt_base->part_base);
510 : }
511 : }
512 :
513 : static int
514 0 : vbdev_gpt_read_gpt(struct spdk_bdev *bdev)
515 : {
516 : struct gpt_base *gpt_base;
517 : struct spdk_bdev_desc *part_base_desc;
518 : int rc;
519 :
520 0 : gpt_base = gpt_base_bdev_init(bdev);
521 0 : if (!gpt_base) {
522 0 : SPDK_ERRLOG("Cannot allocated gpt_base\n");
523 0 : return -1;
524 : }
525 :
526 0 : part_base_desc = spdk_bdev_part_base_get_desc(gpt_base->part_base);
527 0 : gpt_base->ch = spdk_bdev_get_io_channel(part_base_desc);
528 0 : if (gpt_base->ch == NULL) {
529 0 : SPDK_ERRLOG("Failed to get an io_channel.\n");
530 0 : spdk_bdev_part_base_free(gpt_base->part_base);
531 0 : return -1;
532 : }
533 :
534 0 : rc = spdk_bdev_read(part_base_desc, gpt_base->ch, gpt_base->gpt.buf, 0,
535 : gpt_base->gpt.buf_size, gpt_bdev_complete, gpt_base);
536 0 : if (rc < 0) {
537 0 : spdk_put_io_channel(gpt_base->ch);
538 0 : spdk_bdev_part_base_free(gpt_base->part_base);
539 0 : SPDK_ERRLOG("Failed to send bdev_io command\n");
540 0 : return -1;
541 : }
542 :
543 0 : return 0;
544 : }
545 :
546 : static int
547 0 : vbdev_gpt_init(void)
548 : {
549 0 : return 0;
550 : }
551 :
552 : static int
553 0 : vbdev_gpt_get_ctx_size(void)
554 : {
555 0 : return sizeof(struct gpt_io);
556 : }
557 :
558 : static void
559 0 : vbdev_gpt_examine(struct spdk_bdev *bdev)
560 : {
561 : int rc;
562 :
563 : /* A bdev with fewer than 2 blocks cannot have a GPT. Block 0 has
564 : * the MBR and block 1 has the GPT header.
565 : */
566 0 : if (spdk_bdev_get_num_blocks(bdev) < 2) {
567 0 : spdk_bdev_module_examine_done(&gpt_if);
568 0 : return;
569 : }
570 :
571 0 : if (spdk_bdev_get_block_size(bdev) % 512 != 0) {
572 0 : SPDK_DEBUGLOG(vbdev_gpt,
573 : "GPT module does not support block size %" PRIu32 " for bdev %s\n",
574 : spdk_bdev_get_block_size(bdev), spdk_bdev_get_name(bdev));
575 0 : spdk_bdev_module_examine_done(&gpt_if);
576 0 : return;
577 : }
578 :
579 0 : rc = vbdev_gpt_read_gpt(bdev);
580 0 : if (rc) {
581 0 : spdk_bdev_module_examine_done(&gpt_if);
582 0 : SPDK_ERRLOG("Failed to read info from bdev %s\n", spdk_bdev_get_name(bdev));
583 : }
584 : }
585 :
586 0 : SPDK_LOG_REGISTER_COMPONENT(vbdev_gpt)
|