Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libnvme/src/libnvme.ld
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ LIBNVME_3 {
libnvme_transport_handle_set_submit_entry;
libnvme_transport_handle_set_submit_exit;
libnvme_unlink_ctrl;
libnvme_update_block_size;
libnvme_update_key;
libnvme_uuid_from_string;
libnvme_uuid_to_string;
Expand Down
19 changes: 19 additions & 0 deletions libnvme/src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <string.h>
#include <unistd.h>

#include <linux/fs.h>

#include <sys/ioctl.h>
#include <sys/stat.h>

Expand Down Expand Up @@ -93,6 +95,23 @@ __public int libnvme_get_nsid(struct libnvme_transport_handle *hdl, __u32 *nsid)
return 0;
}

__public int libnvme_update_block_size(struct libnvme_transport_handle *hdl,
int block_size)
{
int ret;
int fd = libnvme_transport_handle_get_fd(hdl);

ret = ioctl(fd, BLKBSZSET, &block_size);
if (ret < 0)
return -errno;

ret = ioctl(fd, BLKRRPART);
if (ret < 0)
return -errno;

return 0;
}

void *__libnvme_submit_entry(struct libnvme_transport_handle *hdl,
struct libnvme_passthru_cmd *cmd)
{
Expand Down
13 changes: 13 additions & 0 deletions libnvme/src/nvme/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,16 @@ int libnvme_rescan_ns(struct libnvme_transport_handle *hdl);
* Return: 0 if @nsid was set successfully or -1 with errno set otherwise.
*/
int libnvme_get_nsid(struct libnvme_transport_handle *hdl, __u32 *nsid);

/**
* libnvme_update_block_size() - Update the block size
* @hdl: Transport handle
* @block_size: New block size
*
* Notify the kernel blkdev to update its block size after a block size change.
* This should only be used for namespace handles, not controllers.
*
* Return: 0 if the block size was updated or a negative error code otherwise.
*/
int libnvme_update_block_size(struct libnvme_transport_handle *hdl,
int block_size);
17 changes: 3 additions & 14 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@
#include <string.h>
#include <unistd.h>

#include <linux/fs.h>

#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>


#include <libnvme.h>

#include "common.h"
Expand Down Expand Up @@ -6813,19 +6809,12 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin
* to the given one because blkdev will not
* update by itself without re-opening fd.
*/
if (ioctl(libnvme_transport_handle_get_fd(hdl), BLKBSZSET,
&block_size) < 0) {
err = libnvme_update_block_size(hdl, block_size);
if (err < 0) {
nvme_show_error(
"failed to set block size to %d",
block_size);
return -errno;
}

if (ioctl(libnvme_transport_handle_get_fd(hdl),
BLKRRPART) < 0) {
nvme_show_error(
"failed to re-read partition table");
return -errno;
return err;
}
}
}
Expand Down
Loading