Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
0d608510
Commit
0d608510
authored
Sep 21, 2002
by
Alexander Viro
Committed by
Linus Torvalds
Sep 21, 2002
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PATCH] gendisk for nbd
nbd switched to use of gendisk
parent
e873005d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
35 deletions
+23
-35
drivers/block/nbd.c
drivers/block/nbd.c
+22
-35
include/linux/nbd.h
include/linux/nbd.h
+1
-0
No files found.
drivers/block/nbd.c
View file @
0d608510
...
@@ -59,8 +59,8 @@
...
@@ -59,8 +59,8 @@
static
int
nbd_blksizes
[
MAX_NBD
];
static
int
nbd_blksizes
[
MAX_NBD
];
static
int
nbd_blksize_bits
[
MAX_NBD
];
static
int
nbd_blksize_bits
[
MAX_NBD
];
static
int
nbd_sizes
[
MAX_NBD
];
static
u64
nbd_bytesizes
[
MAX_NBD
];
static
u64
nbd_bytesizes
[
MAX_NBD
];
static
char
nbd_names
[
MAX_NBD
][
7
];
static
struct
nbd_device
nbd_dev
[
MAX_NBD
];
static
struct
nbd_device
nbd_dev
[
MAX_NBD
];
static
devfs_handle_t
devfs_handle
;
static
devfs_handle_t
devfs_handle
;
...
@@ -78,11 +78,7 @@ static int requests_out;
...
@@ -78,11 +78,7 @@ static int requests_out;
static
int
nbd_open
(
struct
inode
*
inode
,
struct
file
*
file
)
static
int
nbd_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
{
int
dev
;
int
dev
=
minor
(
inode
->
i_rdev
);
if
(
!
inode
)
return
-
EINVAL
;
dev
=
minor
(
inode
->
i_rdev
);
if
(
dev
>=
MAX_NBD
)
if
(
dev
>=
MAX_NBD
)
return
-
ENODEV
;
return
-
ENODEV
;
...
@@ -387,21 +383,15 @@ static void do_nbd_request(request_queue_t * q)
...
@@ -387,21 +383,15 @@ static void do_nbd_request(request_queue_t * q)
static
int
nbd_ioctl
(
struct
inode
*
inode
,
struct
file
*
file
,
static
int
nbd_ioctl
(
struct
inode
*
inode
,
struct
file
*
file
,
unsigned
int
cmd
,
unsigned
long
arg
)
unsigned
int
cmd
,
unsigned
long
arg
)
{
{
struct
nbd_device
*
lo
;
int
dev
=
minor
(
inode
->
i_rdev
);
int
dev
,
error
,
temp
;
struct
nbd_device
*
lo
=
&
nbd_dev
[
dev
];
int
error
,
temp
;
struct
request
sreq
;
struct
request
sreq
;
/* Anyone capable of this syscall can do *real bad* things */
/* Anyone capable of this syscall can do *real bad* things */
if
(
!
capable
(
CAP_SYS_ADMIN
))
if
(
!
capable
(
CAP_SYS_ADMIN
))
return
-
EPERM
;
return
-
EPERM
;
if
(
!
inode
)
return
-
EINVAL
;
dev
=
minor
(
inode
->
i_rdev
);
if
(
dev
>=
MAX_NBD
)
return
-
ENODEV
;
lo
=
&
nbd_dev
[
dev
];
switch
(
cmd
)
{
switch
(
cmd
)
{
case
NBD_DISCONNECT
:
case
NBD_DISCONNECT
:
printk
(
KERN_INFO
"NBD_DISCONNECT
\n
"
);
printk
(
KERN_INFO
"NBD_DISCONNECT
\n
"
);
...
@@ -455,15 +445,15 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
...
@@ -455,15 +445,15 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
temp
>>=
1
;
temp
>>=
1
;
}
}
nbd_bytesizes
[
dev
]
&=
~
(
nbd_blksizes
[
dev
]
-
1
);
nbd_bytesizes
[
dev
]
&=
~
(
nbd_blksizes
[
dev
]
-
1
);
nbd_sizes
[
dev
]
=
nbd_bytesizes
[
dev
]
>>
BLOCK_SIZE_BITS
;
set_capacity
(
&
lo
->
disk
,
nbd_bytesizes
[
dev
]
>>
9
)
;
return
0
;
return
0
;
case
NBD_SET_SIZE
:
case
NBD_SET_SIZE
:
nbd_bytesizes
[
dev
]
=
arg
&
~
(
nbd_blksizes
[
dev
]
-
1
);
nbd_bytesizes
[
dev
]
=
arg
&
~
(
nbd_blksizes
[
dev
]
-
1
);
nbd_sizes
[
dev
]
=
nbd_bytesizes
[
dev
]
>>
BLOCK_SIZE_BITS
;
set_capacity
(
&
lo
->
disk
,
nbd_bytesizes
[
dev
]
>>
9
)
;
return
0
;
return
0
;
case
NBD_SET_SIZE_BLOCKS
:
case
NBD_SET_SIZE_BLOCKS
:
nbd_bytesizes
[
dev
]
=
((
u64
)
arg
)
<<
nbd_blksize_bits
[
dev
];
nbd_bytesizes
[
dev
]
=
((
u64
)
arg
)
<<
nbd_blksize_bits
[
dev
];
nbd_sizes
[
dev
]
=
nbd_bytesizes
[
dev
]
>>
BLOCK_SIZE_BITS
;
set_capacity
(
&
lo
->
disk
,
nbd_bytesizes
[
dev
]
>>
9
)
;
return
0
;
return
0
;
case
NBD_DO_IT
:
case
NBD_DO_IT
:
if
(
!
lo
->
file
)
if
(
!
lo
->
file
)
...
@@ -479,25 +469,14 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
...
@@ -479,25 +469,14 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
dev
,
lo
->
queue_head
.
next
,
lo
->
queue_head
.
prev
,
requests_in
,
requests_out
);
dev
,
lo
->
queue_head
.
next
,
lo
->
queue_head
.
prev
,
requests_in
,
requests_out
);
return
0
;
return
0
;
#endif
#endif
case
BLKGETSIZE
:
return
put_user
(
nbd_bytesizes
[
dev
]
>>
9
,
(
unsigned
long
*
)
arg
);
case
BLKGETSIZE64
:
return
put_user
((
u64
)
nbd_bytesizes
[
dev
],
(
u64
*
)
arg
);
}
}
return
-
EINVAL
;
return
-
EINVAL
;
}
}
static
int
nbd_release
(
struct
inode
*
inode
,
struct
file
*
file
)
static
int
nbd_release
(
struct
inode
*
inode
,
struct
file
*
file
)
{
{
struct
nbd_device
*
lo
;
int
dev
=
minor
(
inode
->
i_rdev
);
int
dev
;
struct
nbd_device
*
lo
=
&
nbd_dev
[
dev
];
if
(
!
inode
)
return
-
ENODEV
;
dev
=
minor
(
inode
->
i_rdev
);
if
(
dev
>=
MAX_NBD
)
return
-
ENODEV
;
lo
=
&
nbd_dev
[
dev
];
if
(
lo
->
refcnt
<=
0
)
if
(
lo
->
refcnt
<=
0
)
printk
(
KERN_ALERT
"nbd_release: refcount(%d) <= 0
\n
"
,
lo
->
refcnt
);
printk
(
KERN_ALERT
"nbd_release: refcount(%d) <= 0
\n
"
,
lo
->
refcnt
);
lo
->
refcnt
--
;
lo
->
refcnt
--
;
...
@@ -535,9 +514,9 @@ static int __init nbd_init(void)
...
@@ -535,9 +514,9 @@ static int __init nbd_init(void)
#ifdef MODULE
#ifdef MODULE
printk
(
"nbd: registered device at major %d
\n
"
,
MAJOR_NR
);
printk
(
"nbd: registered device at major %d
\n
"
,
MAJOR_NR
);
#endif
#endif
blk_size
[
MAJOR_NR
]
=
nbd_sizes
;
blk_init_queue
(
BLK_DEFAULT_QUEUE
(
MAJOR_NR
),
do_nbd_request
,
&
nbd_lock
);
blk_init_queue
(
BLK_DEFAULT_QUEUE
(
MAJOR_NR
),
do_nbd_request
,
&
nbd_lock
);
for
(
i
=
0
;
i
<
MAX_NBD
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_NBD
;
i
++
)
{
struct
gendisk
*
disk
=
&
nbd_dev
[
i
].
disk
;
nbd_dev
[
i
].
refcnt
=
0
;
nbd_dev
[
i
].
refcnt
=
0
;
nbd_dev
[
i
].
file
=
NULL
;
nbd_dev
[
i
].
file
=
NULL
;
nbd_dev
[
i
].
magic
=
LO_MAGIC
;
nbd_dev
[
i
].
magic
=
LO_MAGIC
;
...
@@ -548,9 +527,14 @@ static int __init nbd_init(void)
...
@@ -548,9 +527,14 @@ static int __init nbd_init(void)
nbd_blksizes
[
i
]
=
1024
;
nbd_blksizes
[
i
]
=
1024
;
nbd_blksize_bits
[
i
]
=
10
;
nbd_blksize_bits
[
i
]
=
10
;
nbd_bytesizes
[
i
]
=
0x7ffffc00
;
/* 2GB */
nbd_bytesizes
[
i
]
=
0x7ffffc00
;
/* 2GB */
nbd_sizes
[
i
]
=
nbd_bytesizes
[
i
]
>>
BLOCK_SIZE_BITS
;
disk
->
major
=
MAJOR_NR
;
register_disk
(
NULL
,
mk_kdev
(
MAJOR_NR
,
i
),
1
,
&
nbd_fops
,
disk
->
first_minor
=
i
;
nbd_bytesizes
[
i
]
>>
9
);
disk
->
minor_shift
=
0
;
disk
->
fops
=
&
nbd_fops
;
sprintf
(
nbd_names
[
i
],
"nbd%d"
,
i
);
disk
->
major_name
=
nbd_names
[
i
];
set_capacity
(
disk
,
0x3ffffe
);
add_disk
(
disk
);
}
}
devfs_handle
=
devfs_mk_dir
(
NULL
,
"nbd"
,
NULL
);
devfs_handle
=
devfs_mk_dir
(
NULL
,
"nbd"
,
NULL
);
devfs_register_series
(
devfs_handle
,
"%u"
,
MAX_NBD
,
devfs_register_series
(
devfs_handle
,
"%u"
,
MAX_NBD
,
...
@@ -563,6 +547,9 @@ static int __init nbd_init(void)
...
@@ -563,6 +547,9 @@ static int __init nbd_init(void)
static
void
__exit
nbd_cleanup
(
void
)
static
void
__exit
nbd_cleanup
(
void
)
{
{
int
i
;
for
(
i
=
0
;
i
<
MAX_NBD
;
i
++
)
del_gendisk
(
&
nbd_dev
[
i
].
disk
);
devfs_unregister
(
devfs_handle
);
devfs_unregister
(
devfs_handle
);
blk_cleanup_queue
(
BLK_DEFAULT_QUEUE
(
MAJOR_NR
));
blk_cleanup_queue
(
BLK_DEFAULT_QUEUE
(
MAJOR_NR
));
...
...
include/linux/nbd.h
View file @
0d608510
...
@@ -79,6 +79,7 @@ struct nbd_device {
...
@@ -79,6 +79,7 @@ struct nbd_device {
spinlock_t
queue_lock
;
spinlock_t
queue_lock
;
struct
list_head
queue_head
;
/* Requests are added here... */
struct
list_head
queue_head
;
/* Requests are added here... */
struct
semaphore
tx_lock
;
struct
semaphore
tx_lock
;
struct
gendisk
disk
;
};
};
#endif
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment