Index: stand/efi/libefi/efipart.c =================================================================== --- stand/efi/libefi/efipart.c +++ stand/efi/libefi/efipart.c @@ -935,8 +935,9 @@ static int efipart_close(struct open_file *f) { - struct disk_devdesc *dev; + struct disk_devdesc *dev, *currdev; pdinfo_t *pd; + int rc; dev = (struct disk_devdesc *)(f->f_devdata); if (dev == NULL) @@ -946,14 +947,33 @@ if (pd == NULL) return (EINVAL); + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + rc = disk_close(dev); + if (rc != 0) + return (rc); + } pd->pd_open--; + + /* + * Check if this disk is our current filesystem device. + * if it is, preserve pd_bcache to avoid cache flushes. + */ + rc = archsw.arch_getdev((void **)&currdev, NULL, NULL); + if (rc == 0) { + if (strcmp(dev->dd.d_dev->dv_name, + currdev->dd.d_dev->dv_name) == 0 && + dev->dd.d_dev->dv_type == currdev->dd.d_dev->dv_type && + dev->dd.d_unit == currdev->dd.d_unit) { + return (0); + } + } else { + rc = 0; + } + if (pd->pd_open == 0) { - pd->pd_blkio = NULL; bcache_free(pd->pd_bcache); pd->pd_bcache = NULL; } - if (dev->dd.d_dev->dv_type == DEVT_DISK) - return (disk_close(dev)); return (0); } Index: stand/i386/libi386/biosdisk.c =================================================================== --- stand/i386/libi386/biosdisk.c +++ stand/i386/libi386/biosdisk.c @@ -879,22 +879,42 @@ static int bd_close(struct open_file *f) { - struct disk_devdesc *dev; + struct disk_devdesc *dev, *currdev; bdinfo_t *bd; - int rc = 0; + int rc; dev = (struct disk_devdesc *)f->f_devdata; bd = bd_get_bdinfo(&dev->dd); if (bd == NULL) return (EIO); + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + rc = disk_close(dev); + if (rc != 0) + return (rc); + } bd->bd_open--; + + /* + * Check if this disk is our current filesystem device. + * if it is, preserve bd_bcache to avoid cache flushes. + */ + rc = archsw.arch_getdev((void **)&currdev, NULL, NULL); + if (rc == 0) { + if (strcmp(dev->dd.d_dev->dv_name, + currdev->dd.d_dev->dv_name) == 0 && + dev->dd.d_dev->dv_type == currdev->dd.d_dev->dv_type && + dev->dd.d_unit == currdev->dd.d_unit) { + return (0); + } + } else { + rc = 0; + } + if (bd->bd_open == 0) { bcache_free(bd->bd_bcache); bd->bd_bcache = NULL; } - if (dev->dd.d_dev->dv_type == DEVT_DISK) - rc = disk_close(dev); return (rc); } Index: stand/userboot/userboot/userboot_disk.c =================================================================== --- stand/userboot/userboot/userboot_disk.c +++ stand/userboot/userboot/userboot_disk.c @@ -176,15 +176,38 @@ static int userdisk_close(struct open_file *f) { - struct disk_devdesc *dev; + struct disk_devdesc *dev, *currdev; + int rc; dev = (struct disk_devdesc *)f->f_devdata; + if (dev->dd.d_dev->dv_type == DEVT_DISK) { + rc = disk_close(dev); + if (rc != 0) + return (rc); + } ud_info[dev->dd.d_unit].ud_open--; + + /* + * Check if this disk is our current filesystem device. + * if it is, preserve ud_bcache to avoid cache flushes. + */ + rc = archsw.arch_getdev((void **)&currdev, NULL, NULL); + if (rc == 0) { + if (strcmp(dev->dd.d_dev->dv_name, + currdev->dd.d_dev->dv_name) == 0 && + dev->dd.d_dev->dv_type == currdev->dd.d_dev->dv_type && + dev->dd.d_unit == currdev->dd.d_unit) { + return (0); + } + } else { + rc = 0; + } + if (ud_info[dev->dd.d_unit].ud_open == 0) { bcache_free(ud_info[dev->dd.d_unit].ud_bcache); ud_info[dev->dd.d_unit].ud_bcache = NULL; } - return (disk_close(dev)); + return (rc); } static int