static struct lwkt_token disklist_token;
static struct dev_ops disk_ops = {
- { "disk", 0, D_DISK | D_MPSAFE },
+ { "disk", 0, D_DISK | D_MPSAFE | D_TRACKCLOSE },
.d_open = diskopen,
.d_close = diskclose,
.d_read = physread,
return udev_dict_set_cstr(disk->d_cdev, "disk-type", __DECONST(char *, type));
}
+int
+disk_getopencount(struct disk *disk)
+{
+ return disk->d_opencount;
+}
+
static void
_setdiskinfo(struct disk *disk, struct disk_info *info)
{
}
rel_mplock();
+ KKASSERT(dp->d_opencount >= 0);
+ /* If the open was successful, bump open count */
+ if (error == 0)
+ atomic_add_int(&dp->d_opencount, 1);
+
return(error);
}
error = 0;
dp = dev->si_disk;
+ KKASSERT(dp->d_opencount >= 1);
+ /* If this is not the last close, just ignore it */
+ if ((atomic_fetchadd_int(&dp->d_opencount, -1)) > 1)
+ return 0;
+
get_mplock();
dsclose(dev, ap->a_devtype, dp->d_slice);
if (!dsisopen(dp->d_slice)) {
struct dev_ops *d_dev_ops; /* our device switch */
struct dev_ops *d_raw_ops; /* the raw device switch */
u_int d_flags;
+ int d_opencount; /* The current open count */
cdev_t d_rawdev; /* backing raw device */
cdev_t d_cdev; /* special whole-disk part */
struct diskslices *d_slice;
void disk_destroy (struct disk *disk);
void disk_setdiskinfo (struct disk *disk, struct disk_info *info);
int disk_setdisktype(struct disk *disk, const char *type);
+int disk_getopencount(struct disk *disk);
void disk_setdiskinfo_sync(struct disk *disk, struct disk_info *info);
int disk_dumpcheck (cdev_t dev, u_int64_t *count, u_int64_t *blkno, u_int *secsize);
int disk_dumpconf(cdev_t dev, u_int onoff);