NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/54969 (Disk cache is no longer flushed on shutdown)



The following reply was made to PR kern/54969; it has been noted by GNATS.

From: "J. Hannken-Illjes" <hannken%eis.cs.tu-bs.de@localhost>
To: NetBSD GNATS <gnats-bugs%netbsd.org@localhost>
Cc: "Greg A. Woods" <woods%planix.ca@localhost>
Subject: Re: kern/54969 (Disk cache is no longer flushed on shutdown)
Date: Wed, 5 May 2021 15:51:08 +0200

 --Apple-Mail=_02C4883B-991C-4B77-BB72-7F959434AA00
 Content-Type: multipart/mixed;
 	boundary="Apple-Mail=_129BAF62-8E27-4159-8DB4-38C1B290CAA3"
 
 
 --Apple-Mail=_129BAF62-8E27-4159-8DB4-38C1B290CAA3
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=us-ascii
 
 The attached diffs should fix the problem with device-mapper
 devices getting detached too early.
 
 Please report if this fix really works.
 
 --
 J. Hannken-Illjes - hannken%eis.cs.tu-bs.de@localhost - TU Braunschweig
 
 --Apple-Mail=_129BAF62-8E27-4159-8DB4-38C1B290CAA3
 Content-Disposition: attachment;
 	filename=002_dm_unit.diff
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="002_dm_unit.diff"
 Content-Transfer-Encoding: 7bit
 
 dm_unit
 
 Make sure the unit number of device-mapper devices matches our minor number.
 
 diff -r 1e6b25a1c949 -r 497cf11564ea sys/dev/dm/dm_ioctl.c
 --- sys/dev/dm/dm_ioctl.c
 +++ sys/dev/dm/dm_ioctl.c
 @@ -92,18 +92,11 @@
  
  #include "netbsd-dm.h"
  #include "dm.h"
 +#include "ioconf.h"
  
  static uint32_t sc_minor_num;
  uint32_t dm_dev_counter;
  
 -/* Generic cf_data for device-mapper driver */
 -static struct cfdata dm_cfdata = {
 -	.cf_name = "dm",
 -	.cf_atname = "dm",
 -	.cf_fstate = FSTATE_STAR,
 -	.cf_unit = 0
 -};
 -
  #define DM_REMOVE_FLAG(flag, name) do {					\
  	prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag);	\
  	flag &= ~name;							\
 @@ -196,6 +189,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm
  	int r;
  	uint32_t flags;
  	device_t devt;
 +	cfdata_t cf;
  
  	flags = 0;
  	name = NULL;
 @@ -214,7 +208,13 @@ dm_dev_create_ioctl(prop_dictionary_t dm
  		dm_dev_unbusy(dmv);
  		return EEXIST;
  	}
 -	if ((devt = config_attach_pseudo(&dm_cfdata)) == NULL) {
 +	cf = kmem_alloc(sizeof(*cf), KM_SLEEP);
 +	cf->cf_name = dm_cd.cd_name;
 +	cf->cf_atname = dm_cd.cd_name;
 +	cf->cf_unit = (uint64_t)atomic_inc_32_nv(&sc_minor_num);
 +	cf->cf_fstate = FSTATE_NOTFOUND;
 +	if ((devt = config_attach_pseudo(cf)) == NULL) {
 +		kmem_free(cf, sizeof(*cf));
  		aprint_error("Unable to attach pseudo device dm/%s\n", name);
  		return (ENOMEM);
  	}
 @@ -229,7 +229,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm
  	if (name)
  		strlcpy(dmv->name, name, DM_NAME_LEN);
  
 -	dmv->minor = (uint64_t)atomic_inc_32_nv(&sc_minor_num);
 +	dmv->minor = cf->cf_unit;
  	dmv->flags = 0;		/* device flags are set when needed */
  	dmv->ref_cnt = 0;
  	dmv->event_nr = 0;
 @@ -365,6 +365,8 @@ dm_dev_rename_ioctl(prop_dictionary_t dm
  int
  dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
  {
 +	int error;
 +	cfdata_t cf;
  	dm_dev_t *dmv;
  	const char *name, *uuid;
  	uint32_t flags, minor;
 @@ -398,7 +400,11 @@ dm_dev_remove_ioctl(prop_dictionary_t dm
  	 * This will call dm_detach routine which will actually removes
  	 * device.
  	 */
 -	return config_detach(devt, DETACH_QUIET);
 +	cf = device_cfdata(devt);
 +	error = config_detach(devt, DETACH_QUIET);
 +	if (error == 0)
 +		kmem_free(cf, sizeof(*cf));
 +	return error;
  }
  
  /*
 
 --Apple-Mail=_129BAF62-8E27-4159-8DB4-38C1B290CAA3
 Content-Disposition: attachment;
 	filename=003_dm_opencount.diff
 Content-Type: application/octet-stream;
 	x-unix-mode=0644;
 	name="003_dm_opencount.diff"
 Content-Transfer-Encoding: 7bit
 
 dm_opencount
 
 Track the number of cdev and bdev opens and fail dm_detach()
 on open devices unless detach is forced.
 
 PR kern/54969 (Disk cache is no longer flushed on shutdown)
 
 diff -r 497cf11564ea -r 93e32176d61e sys/dev/dm/device-mapper.c
 --- sys/dev/dm/device-mapper.c
 +++ sys/dev/dm/device-mapper.c
 @@ -260,8 +260,17 @@ dm_attach(device_t parent, device_t self
  static int
  dm_detach(device_t self, int flags)
  {
 +	bool busy;
  	dm_dev_t *dmv;
  
 +	dmv = dm_dev_lookup(NULL, NULL, device_unit(self));
 +	mutex_enter(&dmv->diskp->dk_openlock);
 +	busy = (dmv->diskp->dk_openmask != 0 && (flags & DETACH_FORCE) == 0);
 +	mutex_exit(&dmv->diskp->dk_openlock);
 +	dm_dev_unbusy(dmv);
 +	if (busy)
 +		return EBUSY;
 +
  	pmf_device_deregister(self);
  
  	/* Detach device from global device list */
 @@ -334,6 +343,25 @@ dmdestroy(void)
  static int
  dmopen(dev_t dev, int flags, int mode, struct lwp *l)
  {
 +	dm_dev_t *dmv;
 +	struct disk *dk;
 +
 +	dmv = dm_dev_lookup(NULL, NULL, minor(dev));
 +	if (dmv) {
 +		dk = dmv->diskp;
 +		mutex_enter(&dk->dk_openlock);
 +		switch (mode) {
 +		case S_IFCHR:
 +			dk->dk_copenmask |= 1;
 +			break;
 +		case S_IFBLK:
 +			dk->dk_bopenmask |= 1;
 +			break;
 +		}
 +		dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
 +		mutex_exit(&dk->dk_openlock);
 +		dm_dev_unbusy(dmv);
 +	}
  
  	aprint_debug("dm open routine called %" PRIu32 "\n", minor(dev));
  	return 0;
 @@ -342,8 +370,27 @@ dmopen(dev_t dev, int flags, int mode, s
  static int
  dmclose(dev_t dev, int flags, int mode, struct lwp *l)
  {
 +	dm_dev_t *dmv;
 +	struct disk *dk;
  
  	aprint_debug("dm close routine called %" PRIu32 "\n", minor(dev));
 +
 +	dmv = dm_dev_lookup(NULL, NULL, minor(dev));
 +	if (dmv) {
 +		dk = dmv->diskp;
 +		mutex_enter(&dk->dk_openlock);
 +		switch (mode) {
 +		case S_IFCHR:
 +			dk->dk_copenmask &= ~1;
 +			break;
 +		case S_IFBLK:
 +			dk->dk_bopenmask &= ~1;
 +			break;
 +		}
 +		dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
 +		mutex_exit(&dk->dk_openlock);
 +		dm_dev_unbusy(dmv);
 +	}
  	return 0;
  }
  
 
 --Apple-Mail=_129BAF62-8E27-4159-8DB4-38C1B290CAA3--
 
 --Apple-Mail=_02C4883B-991C-4B77-BB72-7F959434AA00
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename=signature.asc
 Content-Type: application/pgp-signature;
 	name=signature.asc
 Content-Description: Message signed with OpenPGP
 
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAEBCAAdFiEE2BL3ha7Xao4WUZVYKoaVJdNr+uEFAmCSoswACgkQKoaVJdNr
 +uEFzQgAgXaa6+Vi1Fs+aPTZpA2XaO6tNCeqOxkUcsLbxD8m2zTiUJ02FkoMaXZL
 1F4kM9cNJl9jFzy0L2GJCoJ6LB8XCyhu2yIOHhVWuCiN0rfAfEW25JnEcdcQAPas
 zvBEfo3p6a3pcWaZzj+suvN6fle7zAET4IUSVEnF0O5Xe1yS71SA/eSAZOqv+C9D
 1CFaWOt8E/CEEA/3s0D6X3g9euFM4kOFxq0SPLB3oZ6OQ6hmLDLtmkbH1Q8RjGh1
 rA0MiyLC1BfmsaiPnLJKSyYzEL3gEDVbc0pQCcxcfRW+aqxr8YybhmbaLYdvfiZe
 KtshrvD39mSAfIl+tx3hrkVlDqgmtw==
 =4lQO
 -----END PGP SIGNATURE-----
 
 --Apple-Mail=_02C4883B-991C-4B77-BB72-7F959434AA00--
 


Home | Main Index | Thread Index | Old Index