Skip to content

Commit 62ab466

Browse files
Martijn Coenenaxboe
authored andcommitted
loop: Move loop_set_status_from_info() and friends up
So we can use it without forward declaration. This is a separate commit to make it easier to verify that this is just a move, without functional modifications. Signed-off-by: Martijn Coenen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0c3796c commit 62ab466

File tree

1 file changed

+103
-103
lines changed

1 file changed

+103
-103
lines changed

drivers/block/loop.c

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,109 @@ static void loop_update_rotational(struct loop_device *lo)
949949
blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
950950
}
951951

952+
static int
953+
loop_release_xfer(struct loop_device *lo)
954+
{
955+
int err = 0;
956+
struct loop_func_table *xfer = lo->lo_encryption;
957+
958+
if (xfer) {
959+
if (xfer->release)
960+
err = xfer->release(lo);
961+
lo->transfer = NULL;
962+
lo->lo_encryption = NULL;
963+
module_put(xfer->owner);
964+
}
965+
return err;
966+
}
967+
968+
static int
969+
loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
970+
const struct loop_info64 *i)
971+
{
972+
int err = 0;
973+
974+
if (xfer) {
975+
struct module *owner = xfer->owner;
976+
977+
if (!try_module_get(owner))
978+
return -EINVAL;
979+
if (xfer->init)
980+
err = xfer->init(lo, i);
981+
if (err)
982+
module_put(owner);
983+
else
984+
lo->lo_encryption = xfer;
985+
}
986+
return err;
987+
}
988+
989+
/**
990+
* loop_set_status_from_info - configure device from loop_info
991+
* @lo: struct loop_device to configure
992+
* @info: struct loop_info64 to configure the device with
993+
*
994+
* Configures the loop device parameters according to the passed
995+
* in loop_info64 configuration.
996+
*/
997+
static int
998+
loop_set_status_from_info(struct loop_device *lo,
999+
const struct loop_info64 *info)
1000+
{
1001+
int err;
1002+
struct loop_func_table *xfer;
1003+
kuid_t uid = current_uid();
1004+
1005+
if ((unsigned int) info->lo_encrypt_key_size > LO_KEY_SIZE)
1006+
return -EINVAL;
1007+
1008+
err = loop_release_xfer(lo);
1009+
if (err)
1010+
return err;
1011+
1012+
if (info->lo_encrypt_type) {
1013+
unsigned int type = info->lo_encrypt_type;
1014+
1015+
if (type >= MAX_LO_CRYPT)
1016+
return -EINVAL;
1017+
xfer = xfer_funcs[type];
1018+
if (xfer == NULL)
1019+
return -EINVAL;
1020+
} else
1021+
xfer = NULL;
1022+
1023+
err = loop_init_xfer(lo, xfer, info);
1024+
if (err)
1025+
return err;
1026+
1027+
lo->lo_offset = info->lo_offset;
1028+
lo->lo_sizelimit = info->lo_sizelimit;
1029+
memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
1030+
memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE);
1031+
lo->lo_file_name[LO_NAME_SIZE-1] = 0;
1032+
lo->lo_crypt_name[LO_NAME_SIZE-1] = 0;
1033+
1034+
if (!xfer)
1035+
xfer = &none_funcs;
1036+
lo->transfer = xfer->transfer;
1037+
lo->ioctl = xfer->ioctl;
1038+
1039+
if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) !=
1040+
(info->lo_flags & LO_FLAGS_AUTOCLEAR))
1041+
lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
1042+
1043+
lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
1044+
lo->lo_init[0] = info->lo_init[0];
1045+
lo->lo_init[1] = info->lo_init[1];
1046+
if (info->lo_encrypt_key_size) {
1047+
memcpy(lo->lo_encrypt_key, info->lo_encrypt_key,
1048+
info->lo_encrypt_key_size);
1049+
lo->lo_key_owner = uid;
1050+
}
1051+
1052+
return 0;
1053+
}
1054+
9521055
static int loop_set_fd(struct loop_device *lo, fmode_t mode,
9531056
struct block_device *bdev, unsigned int arg)
9541057
{
@@ -1070,43 +1173,6 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
10701173
return error;
10711174
}
10721175

1073-
static int
1074-
loop_release_xfer(struct loop_device *lo)
1075-
{
1076-
int err = 0;
1077-
struct loop_func_table *xfer = lo->lo_encryption;
1078-
1079-
if (xfer) {
1080-
if (xfer->release)
1081-
err = xfer->release(lo);
1082-
lo->transfer = NULL;
1083-
lo->lo_encryption = NULL;
1084-
module_put(xfer->owner);
1085-
}
1086-
return err;
1087-
}
1088-
1089-
static int
1090-
loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
1091-
const struct loop_info64 *i)
1092-
{
1093-
int err = 0;
1094-
1095-
if (xfer) {
1096-
struct module *owner = xfer->owner;
1097-
1098-
if (!try_module_get(owner))
1099-
return -EINVAL;
1100-
if (xfer->init)
1101-
err = xfer->init(lo, i);
1102-
if (err)
1103-
module_put(owner);
1104-
else
1105-
lo->lo_encryption = xfer;
1106-
}
1107-
return err;
1108-
}
1109-
11101176
static int __loop_clr_fd(struct loop_device *lo, bool release)
11111177
{
11121178
struct file *filp = NULL;
@@ -1251,72 +1317,6 @@ static int loop_clr_fd(struct loop_device *lo)
12511317
return __loop_clr_fd(lo, false);
12521318
}
12531319

1254-
/**
1255-
* loop_set_status_from_info - configure device from loop_info
1256-
* @lo: struct loop_device to configure
1257-
* @info: struct loop_info64 to configure the device with
1258-
*
1259-
* Configures the loop device parameters according to the passed
1260-
* in loop_info64 configuration.
1261-
*/
1262-
static int
1263-
loop_set_status_from_info(struct loop_device *lo,
1264-
const struct loop_info64 *info)
1265-
{
1266-
int err;
1267-
struct loop_func_table *xfer;
1268-
kuid_t uid = current_uid();
1269-
1270-
if ((unsigned int) info->lo_encrypt_key_size > LO_KEY_SIZE)
1271-
return -EINVAL;
1272-
1273-
err = loop_release_xfer(lo);
1274-
if (err)
1275-
return err;
1276-
1277-
if (info->lo_encrypt_type) {
1278-
unsigned int type = info->lo_encrypt_type;
1279-
1280-
if (type >= MAX_LO_CRYPT)
1281-
return -EINVAL;
1282-
xfer = xfer_funcs[type];
1283-
if (xfer == NULL)
1284-
return -EINVAL;
1285-
} else
1286-
xfer = NULL;
1287-
1288-
err = loop_init_xfer(lo, xfer, info);
1289-
if (err)
1290-
return err;
1291-
1292-
lo->lo_offset = info->lo_offset;
1293-
lo->lo_sizelimit = info->lo_sizelimit;
1294-
memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
1295-
memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE);
1296-
lo->lo_file_name[LO_NAME_SIZE-1] = 0;
1297-
lo->lo_crypt_name[LO_NAME_SIZE-1] = 0;
1298-
1299-
if (!xfer)
1300-
xfer = &none_funcs;
1301-
lo->transfer = xfer->transfer;
1302-
lo->ioctl = xfer->ioctl;
1303-
1304-
if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) !=
1305-
(info->lo_flags & LO_FLAGS_AUTOCLEAR))
1306-
lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
1307-
1308-
lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
1309-
lo->lo_init[0] = info->lo_init[0];
1310-
lo->lo_init[1] = info->lo_init[1];
1311-
if (info->lo_encrypt_key_size) {
1312-
memcpy(lo->lo_encrypt_key, info->lo_encrypt_key,
1313-
info->lo_encrypt_key_size);
1314-
lo->lo_key_owner = uid;
1315-
}
1316-
1317-
return 0;
1318-
}
1319-
13201320
static int
13211321
loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
13221322
{

0 commit comments

Comments
 (0)