Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize ioctl #126

Merged
merged 7 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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 fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ int fuse_restart_requests(struct fuse_conn *fc);
ssize_t pxd_add(struct fuse_conn *fc, struct pxd_add_ext_out *add);
ssize_t pxd_remove(struct fuse_conn *fc, struct pxd_remove_out *remove);
ssize_t pxd_update_size(struct fuse_conn *fc, struct pxd_update_size_out *update_size);
ssize_t pxd_ioc_update_size(struct fuse_conn *fc, struct pxd_update_size_out *update_size);
ssize_t pxd_read_init(struct fuse_conn *fc, struct iov_iter *iter);

// fastpath extension
Expand Down
38 changes: 38 additions & 0 deletions pxd.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ static long pxd_ioctl_init(struct file *file, void __user *argp)
return pxd_read_init(&ctx->fc, &iter);
}

static long pxd_ioctl_resize(struct file *file, void __user *argp)
{
struct pxd_context *ctx = NULL;
struct pxd_update_size_out update_args;
long ret = 0;

if (copy_from_user(&update_args, argp, sizeof(update_args))) {
return -EFAULT;
}

if (!ctx || ctx->id >= pxd_num_contexts_exported) {
prabirpaul marked this conversation as resolved.
Show resolved Hide resolved
return -EFAULT;
}

ctx = &pxd_contexts[update_args.context_id];
if (update_args.context_id >= pxd_num_contexts_exported) {
printk("%s : invalid context: %d\n", __func__, update_args.context_id);
return -EFAULT;
}

printk(KERN_ALERT "%s: id: %llu size: %lu ctx_id: %d\n", __func__,
update_args.dev_id, update_args.size, update_args.context_id);
ret = pxd_ioc_update_size(&ctx->fc, &update_args);
return ret;
}

static long pxd_ioctl_run_user_queue(struct file *file)
{
struct pxd_context *ctx = container_of(file->f_op, struct pxd_context, fops);
Expand Down Expand Up @@ -183,6 +209,8 @@ static long pxd_control_ioctl(struct file *file, unsigned int cmd, unsigned long
return pxd_ioctl_init(file, (void __user *)arg);
case PXD_IOC_RUN_USER_QUEUE:
return pxd_ioctl_run_user_queue(file);
case PXD_IOC_RESIZE:
return pxd_ioctl_resize(file, (void __user *)arg);
default:
return -ENOTTY;
}
Expand Down Expand Up @@ -1023,6 +1051,11 @@ ssize_t pxd_remove(struct fuse_conn *fc, struct pxd_remove_out *remove)
}

ssize_t pxd_update_size(struct fuse_conn *fc, struct pxd_update_size_out *update_size)
{
return -EOPNOTSUPP;
}

ssize_t pxd_ioc_update_size(struct fuse_conn *fc, struct pxd_update_size_out *update_size)
{
bool found = false;
struct pxd_context *ctx = container_of(fc, struct pxd_context, fc);
Expand All @@ -1044,6 +1077,11 @@ ssize_t pxd_update_size(struct fuse_conn *fc, struct pxd_update_size_out *update
goto out;
}

if (update_size->size < pxd_dev->size) {
spin_unlock(&pxd_dev->lock);
err = -EINVAL;
goto out;
}
(void)get_device(&pxd_dev->dev);

set_capacity(pxd_dev->disk, update_size->size / SECTOR_SIZE);
Expand Down
12 changes: 7 additions & 5 deletions pxd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define PXD_DEV "pxd/pxd" /**< block device prefix */
#define PXD_DEV_PATH "/dev/" PXD_DEV /**< block device path prefix */

#define PXD_VERSION 10 /**< driver version */
#define PXD_VERSION 11 /**< driver version */

#define PXD_NUM_CONTEXTS 11 /**< Total available control devices */
#define PXD_NUM_CONTEXT_EXPORTED 1 /**< Available for external use */
Expand All @@ -30,9 +30,10 @@
#define PXD_IOC_GET_VERSION _IO(PXD_IOCTL_MAGIC, 2) /* 0x505802 */
#define PXD_IOC_INIT _IO(PXD_IOCTL_MAGIC, 3) /* 0x505803 */
#define PXD_IOC_RUN_USER_QUEUE _IO(PXD_IOCTL_MAGIC, 4) /* 0x505804 */
#define PXD_IOC_RUN_IO_QUEUE _IO(PXD_IOCTL_MAGIC, 5)
#define PXD_IOC_REGISTER_FILE _IO(PXD_IOCTL_MAGIC, 6)
#define PXD_IOC_UNREGISTER_FILE _IO(PXD_IOCTL_MAGIC, 7)
#define PXD_IOC_RUN_IO_QUEUE _IO(PXD_IOCTL_MAGIC, 5) /* 0x505805 */
#define PXD_IOC_REGISTER_FILE _IO(PXD_IOCTL_MAGIC, 6) /* 0x505806 */
#define PXD_IOC_UNREGISTER_FILE _IO(PXD_IOCTL_MAGIC, 7) /* 0x505807 */
#define PXD_IOC_RESIZE _IO(PXD_IOCTL_MAGIC, 8) /* 0x505808 */

#define PXD_MAX_DEVICES 512 /**< maximum number of devices supported */
#define PXD_MAX_IO (1024*1024) /**< maximum io size in bytes */
Expand Down Expand Up @@ -155,11 +156,12 @@ struct pxd_read_data_out {
};

/**
* PXD_UPDATE_SIZE request from user space
* PXD_UPDATE_SIZE ioctl from user space
*/
struct pxd_update_size_out {
uint64_t dev_id;
size_t size;
int context_id;
};

/**
Expand Down