bcache: Use bcache without formatting existing device
PATCH 1/1 bcache: Use bcache without formatting existing device
v2: Fixed small typo
Introducing a bcache control device (/dev/bcache_ctrl) that allows communicating to the driver from user space via IOCTL. The only IOCTL commands currently implemented, receives a struct cache_sb and uses it to register the backing device.
--- drivers/md/bcache/Makefile | 2 +- drivers/md/bcache/control.c | 117 ++++++++++++++++++++++++++++++++ drivers/md/bcache/control.h | 12 ++++ drivers/md/bcache/ioctl_codes.h | 19 ++++++ drivers/md/bcache/super.c | 62 ++++++++++++----- drivers/md/bcache/sysfs.c | 4 ++ drivers/md/bcache/writeback.h | 2 +- 7 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 drivers/md/bcache/control.c create mode 100644 drivers/md/bcache/control.h create mode 100644 drivers/md/bcache/ioctl_codes.h
drivers/md/bcache/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_BCACHE) += bcache.o bcache-y := alloc.o bset.o btree.o closure.o debug.o extents.o\ io.o journal.o movinggc.o request.o stats.o super.o sysfs.o trace.o\ - util.o writeback.o features.o + util.o writeback.o features.o control.o
drivers/md/bcache/control.c new file +117 -0
117 lines not on this page · raw message
drivers/md/bcache/control.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BCACHE_CONTROL_H__ +#define __BCACHE_CONTROL_H__ + +#include "ioctl_codes.h" + +int __init bch_ctrl_device_init (void ); +void bch_ctrl_device_deinit (void ); + +ssize_t register_bcache_ioctl (struct bch_register_device *brd); + +#endif
drivers/md/bcache/ioctl_codes.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BCACHE_IOCTL_CODES_H__ +#define __BCACHE_IOCTL_CODES_H__ + +#include <linux/ioctl.h> +#include <linux/types.h> + +struct bch_register_device { +const char *dev_name; +size_t size; +struct cache_sb *sb; +}; + +#define BCH_IOCTL_MAGIC (0xBC) + +/** Start new cache instance, load cache or recover cache */ +#define BCH_IOCTL_REGISTER_DEVICE _IOWR(BCH_IOCTL_MAGIC, 1, struct bch_register_device) + +#endif
drivers/md/bcache/super.c +46 -16
145 lines not on this page · raw message
drivers/md/bcache/sysfs.c +4 -0
@@ -379,6 +379,10 @@ STORE(__cached_dev)if (v <0 )return v; +// XXX(atom): Devices created by IOCTL don't support changing cache mode +if (!dc->sb_disk) +return -EINVAL ; +if ((unsigned int ) v !=BDEV_CACHE_MODE (&dc->sb)) {SET_BDEV_CACHE_MODE (&dc->sb, v);bch_write_bdev_super (dc,NULL );
drivers/md/bcache/writeback.h +1 -1
@@ -135,7 +135,7 @@ static inline void bch_writeback_add(struct cached_dev *dc) {if (!atomic_read (&dc->has_dirty) && !atomic_xchg (&dc->has_dirty,1 )) { -if (BDEV_STATE (&dc->sb) !=BDEV_STATE_DIRTY ) { +if (dc->sb_disk &&BDEV_STATE (&dc->sb) !=BDEV_STATE_DIRTY ) {SET_BDEV_STATE (&dc->sb,BDEV_STATE_DIRTY );/* XXX: should do this synchronously */ bch_write_bdev_super (dc,NULL );
Signature · 18 lines
2.25.1 -- The contents of this email are confidential. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to this message and deleting it from your computer. Thank you. Devo, Inc; [email protected] <mailto:[email protected]>; Calle Estébanez Calderón 3-5, 5th Floor. Madrid, Spain 28020
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Andrea,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.17-rc7 next-20220309]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3bf7edc84a9eb4007dd9a0cb8878a7e1d5ec6a3b config: riscv-buildonly-randconfig-r002-20220310 (https://download.01.org/0day-ci/archive/20220310/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 276ca87382b8f16a65bddac700202924228982f6)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/b5073e4ece2a86f002ca66fb1d864034c12be3e2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 git checkout b5073e4ece2a86f002ca66fb1d864034c12be3e2
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/md/bcache/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/md/bcache/control.c:18:6: warning: no previous prototype for function 'bch_service_ioctl_ctrl' [-Wmissing-prototypes]
long bch_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
^ drivers/md/bcache/control.c:18:1: note: declare 'static' if the function is not intended to be used outside of this translation unit long bch_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
^
static
1 warning generated.
vim +/bch_service_ioctl_ctrl +18 drivers/md/bcache/control.c
15
16 /* this handles IOCTL for /dev/bcache_ctrl */
17 /*********************************************/
> 18 long bch_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
19 unsigned long arg)
20 {
21 int retval = 0;
22
23 if (_IOC_TYPE(cmd) != BCH_IOCTL_MAGIC)
24 return -EINVAL;
25
26 if (!capable(CAP_SYS_ADMIN)) {
27 /* Must be root to issue ioctls */
28 return -EPERM;
29 }
30
31 switch (cmd) {
32 case BCH_IOCTL_REGISTER_DEVICE: {
33 struct bch_register_device *cmd_info;
34
35 cmd_info = vmalloc(sizeof(struct bch_register_device));
36 if (!cmd_info)
37 return -ENOMEM;
38
39 if (copy_from_user(cmd_info, (void __user *)arg,
40 sizeof(struct bch_register_device))) {
41 pr_err("Cannot copy cmd info from user space\n");
42 vfree(cmd_info);
43 return -EINVAL;
44 }
45
46 retval = register_bcache_ioctl(cmd_info);
47
48 vfree(cmd_info);
49 return retval;
50 }
51
52 default:
53 return -EINVAL;
54 }
55 }
56 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Andrea,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.17-rc7 next-20220309]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3bf7edc84a9eb4007dd9a0cb8878a7e1d5ec6a3b config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220310/[email protected]/config) compiler: gcc-9 (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/b5073e4ece2a86f002ca66fb1d864034c12be3e2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 git checkout b5073e4ece2a86f002ca66fb1d864034c12be3e2
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/md/bcache/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/md/bcache/control.c:18:6: warning: no previous prototype for 'bch_service_ioctl_ctrl' [-Wmissing-prototypes]
18 | long bch_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
| ^~~~~~~~~~~~~~~~~~~~~~
vim +/bch_service_ioctl_ctrl +18 drivers/md/bcache/control.c
15
16 /* this handles IOCTL for /dev/bcache_ctrl */
17 /*********************************************/
> 18 long bch_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
19 unsigned long arg)
20 {
21 int retval = 0;
22
23 if (_IOC_TYPE(cmd) != BCH_IOCTL_MAGIC)
24 return -EINVAL;
25
26 if (!capable(CAP_SYS_ADMIN)) {
27 /* Must be root to issue ioctls */
28 return -EPERM;
29 }
30
31 switch (cmd) {
32 case BCH_IOCTL_REGISTER_DEVICE: {
33 struct bch_register_device *cmd_info;
34
35 cmd_info = vmalloc(sizeof(struct bch_register_device));
36 if (!cmd_info)
37 return -ENOMEM;
38
39 if (copy_from_user(cmd_info, (void __user *)arg,
40 sizeof(struct bch_register_device))) {
41 pr_err("Cannot copy cmd info from user space\n");
42 vfree(cmd_info);
43 return -EINVAL;
44 }
45
46 retval = register_bcache_ioctl(cmd_info);
47
48 vfree(cmd_info);
49 return retval;
50 }
51
52 default:
53 return -EINVAL;
54 }
55 }
56 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build bot[RFC PATCH] bcache: bch_service_ioctl_ctrl() can be static
In reply to Andrea Tomassettidrivers/md/bcache/control.c:18:6: warning: symbol 'bch_service_ioctl_ctrl' was not declared. Should it be static?
drivers/md/bcache/control.c:18:6: warning: symbol 'bch_service_ioctl_ctrl' was not declared. Should it be static?
--- drivers/md/bcache/control.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/control.c +1 -1
@@ -15,7 +15,7 @@ static struct bch_ctrl_device _control_device;/* this handles IOCTL for /dev/bcache_ctrl */ /*********************************************/ -long bch_service_ioctl_ctrl (struct file *filp,unsigned int cmd, +static long bch_service_ioctl_ctrl (struct file *filp,unsigned int cmd,unsigned long arg) {int retval =0 ;
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Andrea,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.17-rc7 next-20220309]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3bf7edc84a9eb4007dd9a0cb8878a7e1d5ec6a3b config: i386-randconfig-s002 (https://download.01.org/0day-ci/archive/20220310/[email protected]/config) compiler: gcc-9 (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 reproduce: # apt-get install sparse # sparse version: v0.6.4-dirty # https://github.com/0day-ci/linux/commit/b5073e4ece2a86f002ca66fb1d864034c12be3e2 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Andrea-Tomassetti/bcache-Use-bcache-without-formatting-existing-device/20220310-165353 git checkout b5073e4ece2a86f002ca66fb1d864034c12be3e2 # save the config file to linux build tree mkdir build_dir make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash drivers/md/bcache/
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> drivers/md/bcache/control.c:18:6: sparse: sparse: symbol 'bch_service_ioctl_ctrl' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]