@@ -108,8 +108,6 @@ static inline void ubd_set_bit(__u64 bit, unsigned char *data)
108
108
static DEFINE_MUTEX (ubd_lock );
109
109
static DEFINE_MUTEX (ubd_mutex ); /* replaces BKL, might not be needed */
110
110
111
- static int ubd_open (struct gendisk * disk , blk_mode_t mode );
112
- static void ubd_release (struct gendisk * disk );
113
111
static int ubd_ioctl (struct block_device * bdev , blk_mode_t mode ,
114
112
unsigned int cmd , unsigned long arg );
115
113
static int ubd_getgeo (struct block_device * bdev , struct hd_geometry * geo );
@@ -118,8 +116,6 @@ static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
118
116
119
117
static const struct block_device_operations ubd_blops = {
120
118
.owner = THIS_MODULE ,
121
- .open = ubd_open ,
122
- .release = ubd_release ,
123
119
.ioctl = ubd_ioctl ,
124
120
.compat_ioctl = blkdev_compat_ptr_ioctl ,
125
121
.getgeo = ubd_getgeo ,
@@ -152,7 +148,6 @@ struct ubd {
152
148
* backing or the cow file. */
153
149
char * file ;
154
150
char * serial ;
155
- int count ;
156
151
int fd ;
157
152
__u64 size ;
158
153
struct openflags boot_openflags ;
@@ -178,7 +173,6 @@ struct ubd {
178
173
#define DEFAULT_UBD { \
179
174
.file = NULL, \
180
175
.serial = NULL, \
181
- .count = 0, \
182
176
.fd = -1, \
183
177
.size = -1, \
184
178
.boot_openflags = OPEN_FLAGS, \
@@ -873,6 +867,13 @@ static int ubd_add(int n, char **error_out)
873
867
goto out ;
874
868
}
875
869
870
+ err = ubd_open_dev (ubd_dev );
871
+ if (err ) {
872
+ pr_err ("ubd%c: Can't open \"%s\": errno = %d\n" ,
873
+ 'a' + n , ubd_dev -> file , - err );
874
+ goto out ;
875
+ }
876
+
876
877
ubd_dev -> size = ROUND_BLOCK (ubd_dev -> size );
877
878
878
879
ubd_dev -> tag_set .ops = & ubd_mq_ops ;
@@ -884,7 +885,7 @@ static int ubd_add(int n, char **error_out)
884
885
885
886
err = blk_mq_alloc_tag_set (& ubd_dev -> tag_set );
886
887
if (err )
887
- goto out ;
888
+ goto out_close ;
888
889
889
890
disk = blk_mq_alloc_disk (& ubd_dev -> tag_set , & lim , ubd_dev );
890
891
if (IS_ERR (disk )) {
@@ -919,6 +920,8 @@ static int ubd_add(int n, char **error_out)
919
920
put_disk (disk );
920
921
out_cleanup_tags :
921
922
blk_mq_free_tag_set (& ubd_dev -> tag_set );
923
+ out_close :
924
+ ubd_close_dev (ubd_dev );
922
925
out :
923
926
return err ;
924
927
}
@@ -1014,13 +1017,14 @@ static int ubd_remove(int n, char **error_out)
1014
1017
if (ubd_dev -> file == NULL )
1015
1018
goto out ;
1016
1019
1017
- /* you cannot remove a open disk */
1018
- err = - EBUSY ;
1019
- if (ubd_dev -> count > 0 )
1020
- goto out ;
1021
-
1022
1020
if (ubd_dev -> disk ) {
1021
+ /* you cannot remove a open disk */
1022
+ err = - EBUSY ;
1023
+ if (disk_openers (ubd_dev -> disk ))
1024
+ goto out ;
1025
+
1023
1026
del_gendisk (ubd_dev -> disk );
1027
+ ubd_close_dev (ubd_dev );
1024
1028
put_disk (ubd_dev -> disk );
1025
1029
}
1026
1030
@@ -1143,36 +1147,6 @@ static int __init ubd_driver_init(void){
1143
1147
1144
1148
device_initcall (ubd_driver_init );
1145
1149
1146
- static int ubd_open (struct gendisk * disk , blk_mode_t mode )
1147
- {
1148
- struct ubd * ubd_dev = disk -> private_data ;
1149
- int err = 0 ;
1150
-
1151
- mutex_lock (& ubd_mutex );
1152
- if (ubd_dev -> count == 0 ){
1153
- err = ubd_open_dev (ubd_dev );
1154
- if (err ){
1155
- printk (KERN_ERR "%s: Can't open \"%s\": errno = %d\n" ,
1156
- disk -> disk_name , ubd_dev -> file , - err );
1157
- goto out ;
1158
- }
1159
- }
1160
- ubd_dev -> count ++ ;
1161
- out :
1162
- mutex_unlock (& ubd_mutex );
1163
- return err ;
1164
- }
1165
-
1166
- static void ubd_release (struct gendisk * disk )
1167
- {
1168
- struct ubd * ubd_dev = disk -> private_data ;
1169
-
1170
- mutex_lock (& ubd_mutex );
1171
- if (-- ubd_dev -> count == 0 )
1172
- ubd_close_dev (ubd_dev );
1173
- mutex_unlock (& ubd_mutex );
1174
- }
1175
-
1176
1150
static void cowify_bitmap (__u64 io_offset , int length , unsigned long * cow_mask ,
1177
1151
__u64 * cow_offset , unsigned long * bitmap ,
1178
1152
__u64 bitmap_offset , unsigned long * bitmap_words ,
0 commit comments