# HG changeset patch # User Pascal Bellard # Date 1678538033 0 # Node ID c81179c4b10617c3447a23629613c71ae97bdd6c # Parent e6abe3abd527523d5ca53d8ca97ad547af23e6c0 linux-cloop: update cloop.u diff -r e6abe3abd527 -r c81179c4b106 linux-cloop/stuff/cloop.u --- a/linux-cloop/stuff/cloop.u Sat Mar 11 09:15:29 2023 +0000 +++ b/linux-cloop/stuff/cloop.u Sat Mar 11 12:33:53 2023 +0000 @@ -327,26 +327,23 @@ xz_dec_reset(clo->xzdecoderstate); err = xz_dec_run(clo->xzdecoderstate, &clo->xz_buffer); if (err == XZ_STREAM_END || err == XZ_OK) -@@ -309,16 +304,12 @@ +@@ -309,9 +304,12 @@ while (buf_done < buf_len) { size_t size = buf_len - buf_done, size_read; -- mm_segment_t old_fs; - /* kernel_read() only supports 32 bit offsets, so we use vfs_read() instead. */ - /* int size_read = kernel_read(f, pos, buf + buf_done, size); */ -- - // mutex_lock(&clo->clo_rq_mutex); -- old_fs = get_fs(); -- set_fs(KERNEL_DS); +- size_read = kernel_read(f, buf + buf_done, size, &pos); +- // mutex_unlock(&clo->clo_rq_mutex); ++ /* kernel_read() only supports 32 bit offsets, so we use vfs_read() instead. */ ++ /* int size_read = kernel_read(f, pos, buf + buf_done, size); */ + mm_segment_t old_fs = get_fs(); + set_fs(get_ds()); - size_read = vfs_read(f, (void __user *)(buf + buf_done), size, &pos); - set_fs(old_fs); -- // mutex_unlock(&clo->clo_rq_mutex); ++ size_read = vfs_read(f, (void __user *)(buf + buf_done), size, &pos); ++ set_fs(old_fs); if(size_read <= 0) { -@@ -358,8 +349,8 @@ +@@ -351,8 +349,8 @@ return i; } @@ -357,7 +354,7 @@ /* Load one compressed block from the file. */ if(compressed_block_offset > 0 && compressed_block_len >= 0) /* sanity check */ -@@ -369,12 +360,12 @@ +@@ -362,12 +360,12 @@ if (n!= compressed_block_len) { printk(KERN_ERR "%s: error while reading %lu bytes @ %llu from file %s\n", @@ -372,7 +369,7 @@ return -1; } -@@ -382,14 +373,16 @@ +@@ -375,14 +373,16 @@ if(++clo->current_bufnum >= clo->num_buffered_blocks) clo->current_bufnum = 0; /* Do the uncompression */ @@ -392,7 +389,7 @@ clo->buffered_blocknum[clo->current_bufnum] = -1; return -1; } -@@ -397,107 +390,146 @@ +@@ -390,107 +390,146 @@ return clo->current_bufnum; } @@ -451,9 +448,7 @@ + unsigned long len = bvec.bv_len; + char *to_ptr = kmap(bvec.bv_page) + bvec.bv_offset; + while(len > 0) - { -- ret = BLK_STS_IOERR; -- break; /* invalid data, leave inner loop */ ++ { + u_int32_t length_in_buffer; + loff_t block_offset = offset; + u_int32_t offset_in_buffer; @@ -510,7 +505,9 @@ + err = wait_event_interruptible(clo->clo_event, !list_empty(&clo->clo_list) || + kthread_should_stop()); + if(unlikely(err)) -+ { + { +- ret = BLK_STS_IOERR; +- break; /* invalid data, leave inner loop */ + DEBUGP(KERN_ERR "cloop thread activated on error!? Continuing.\n"); + continue; } @@ -631,7 +628,7 @@ } /* Read header, flags and offsets from already opened file */ -@@ -508,7 +540,7 @@ +@@ -501,7 +540,7 @@ char *bbuf=NULL; unsigned int bbuf_size = 0; const unsigned int header_size = sizeof(struct cloop_head); @@ -640,7 +637,34 @@ loff_t fs_read_position = 0, header_pos[2]; int isblkdev, bytes_read, error = 0; if (clo->suspended) return error; -@@ -581,29 +613,19 @@ +@@ -521,7 +560,7 @@ + } + clo->backing_file = file; + clo->backing_inode= inode ; +- clo->underlying_total_size = (isblkdev) ? file->f_mapping->host->i_size : inode->i_size; ++ clo->underlying_total_size = (isblkdev) ? inode->i_bdev->bd_inode->i_size : inode->i_size; + if(clo->underlying_total_size < header_size) + { + printk(KERN_ERR "%s: %llu bytes (must be >= %u bytes)\n", +@@ -531,7 +570,7 @@ + } + if(isblkdev) + { +- struct request_queue *q = bdev_get_queue(I_BDEV(file->f_mapping->host)); ++ struct request_queue *q = bdev_get_queue(inode->i_bdev); + blk_queue_max_hw_sectors(clo->clo_queue, queue_max_hw_sectors(q)); /* Renamed in 2.6.34 */ + blk_queue_max_segments(clo->clo_queue, queue_max_segments(q)); /* Renamed in 2.6.34 */ + /* blk_queue_max_hw_segments(clo->clo_queue, queue_max_hw_segments(q)); */ /* Removed in 2.6.34 */ +@@ -540,7 +579,7 @@ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) + blk_queue_merge_bvec(clo->clo_queue, q->merge_bvec_fn); + #endif +- clo->underlying_blksize = block_size(I_BDEV(file->f_mapping->host)); ++ clo->underlying_blksize = block_size(inode->i_bdev); + } + else + clo->underlying_blksize = PAGE_SIZE; +@@ -574,29 +613,19 @@ goto error_release; } memcpy(&clo->head, bbuf, header_size); @@ -674,7 +698,7 @@ cloop_name, cloop_name); error=-EBADF; goto error_release; } -@@ -613,67 +635,133 @@ +@@ -606,67 +635,133 @@ cloop_name, clo->head.block_size); error=-EBADF; goto error_release; } @@ -785,13 +809,18 @@ + } + /* Read them offsets! */ + if(clo->header_first) ++ { ++ total_bytes = total_offsets * sizeof(struct block_info); ++ fs_read_position = sizeof(struct cloop_head); ++ } ++ else { - printk(KERN_ERR "%s: Bad file %s, read() %lu bytes @ %llu returned %d.\n", - cloop_name, clo->underlying_filename, (unsigned long)clo->underlying_blksize, fs_read_position, (int)bytes_read); - error=-EBADF; - goto error_release; -+ total_bytes = total_offsets * sizeof(struct block_info); -+ fs_read_position = sizeof(struct cloop_head); ++ total_bytes = total_offsets * sizeof(loff_t); ++ fs_read_position = clo->underlying_total_size - sizeof(struct cloop_head) - total_bytes; } - /* remember where to read the next blk from file */ - fs_read_position += bytes_read; @@ -800,16 +829,11 @@ - bytes_read / sizeof(loff_t)); - DEBUGP(KERN_INFO "cloop: parsing %d offsets %d to %d\n", num_readable, offsets_read, offsets_read+num_readable-1); - for (i=0,offset=0; i 0) -+ total_bytes = total_offsets * sizeof(loff_t); -+ fs_read_position = clo->underlying_total_size - sizeof(struct cloop_head) - total_bytes; -+ } -+ for(n=0;nunderlying_total_size - fs_read_position); + if(bytes_readable <= 0) break; /* Done */ @@ -847,7 +871,7 @@ clo->num_buffered_blocks = (buffers > 0 && clo->head.block_size >= 512) ? (buffers / clo->head.block_size) : 1; clo->buffered_blocknum = cloop_malloc(clo->num_buffered_blocks * sizeof (u_int32_t)); -@@ -705,36 +793,14 @@ +@@ -698,36 +793,14 @@ cloop_name, clo->largest_block); error=-ENOMEM; goto error_release_free_buffer; } @@ -889,7 +913,7 @@ if(preload > 0) { clo->preload_array_size = ((preload<=clo->head.num_blocks)?preload:clo->head.num_blocks); -@@ -780,6 +846,7 @@ +@@ -773,6 +846,7 @@ clo->preload_array_size = clo->preload_size = 0; } } @@ -897,7 +921,7 @@ /* Uncheck */ return error; error_release_free_all: -@@ -794,9 +861,13 @@ +@@ -787,9 +861,13 @@ } if (clo->buffered_blocknum) { cloop_free(clo->buffered_blocknum, sizeof(int)*clo->num_buffered_blocks); clo->buffered_blocknum=NULL; } error_release_free: @@ -912,7 +936,16 @@ if(bbuf) cloop_free(bbuf, clo->underlying_blksize); if(clo->underlying_filename) { kfree(clo->underlying_filename); clo->underlying_filename=NULL; } clo->backing_file=NULL; -@@ -829,6 +900,7 @@ +@@ -809,7 +887,7 @@ + file = fget(arg); /* get filp struct from ioctl arg fd */ + if(!file) return -EBADF; + error=cloop_set_file(cloop_num,file); +- set_disk_ro(clo->clo_disk, true); ++ set_device_ro(bdev, 1); + if(error) fput(file); + return error; + } +@@ -822,6 +900,7 @@ if(clo->refcnt > 1) /* we needed one fd for the ioctl */ return -EBUSY; if(filp==NULL) return -EINVAL; @@ -920,7 +953,7 @@ if(filp!=initial_file) fput(filp); else -@@ -839,7 +911,7 @@ +@@ -832,7 +911,7 @@ clo->backing_file = NULL; clo->backing_inode = NULL; if(clo->underlying_filename) { kfree(clo->underlying_filename); clo->underlying_filename=NULL; } @@ -929,7 +962,7 @@ if(clo->preload_cache) { int i; -@@ -1054,15 +1126,15 @@ +@@ -1047,15 +1126,15 @@ case LOOP_CLR_FD: /* Change arg */ case LOOP_GET_STATUS64: /* Change arg */ case LOOP_SET_STATUS64: /* Change arg */ @@ -949,7 +982,7 @@ } #endif -@@ -1093,7 +1165,7 @@ +@@ -1086,7 +1165,7 @@ cloop_dev[cloop_num]->refcnt-=1; } @@ -958,7 +991,7 @@ { owner: THIS_MODULE, open: cloop_open, -@@ -1105,12 +1177,6 @@ +@@ -1098,12 +1177,6 @@ /* locked_ioctl ceased to exist in 2.6.36 */ }; @@ -971,11 +1004,12 @@ static int cloop_register_blkdev(int major_nr) { return register_blkdev(major_nr, cloop_name); -@@ -1124,37 +1190,33 @@ +@@ -1117,73 +1190,45 @@ static int cloop_alloc(int cloop_num) { - struct cloop_device *clo = (struct cloop_device *) cloop_malloc(sizeof(struct cloop_device)); +- int error = -ENOMEM; + struct cloop_device *clo = (struct cloop_device *) cloop_malloc(sizeof(struct cloop_device));; if(clo == NULL) goto error_out; cloop_dev[cloop_num] = clo; @@ -990,6 +1024,7 @@ - clo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING; - clo->tag_set.driver_data = clo; - if(blk_mq_alloc_tag_set(&clo->tag_set)) goto error_out_free_clo; +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) - clo->clo_queue = blk_mq_init_queue(&clo->tag_set); - if(IS_ERR(clo->clo_queue)) + clo->clo_thread = NULL; @@ -1004,47 +1039,87 @@ - goto error_out_free_tags; + goto error_out; } - clo->clo_queue->queuedata = clo; -- blk_queue_max_hw_sectors(clo->clo_queue, BLK_DEF_MAX_SECTORS); +- clo->clo_disk = alloc_disk(1); +-#else +- clo->clo_disk = blk_mq_alloc_disk(&clo->tag_set, NULL); ++ clo->clo_queue->queuedata = clo; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, clo->clo_queue); + queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, clo->clo_queue); -+#endif - clo->clo_disk = alloc_disk(1); + #endif ++ clo->clo_disk = alloc_disk(1); if(!clo->clo_disk) { printk(KERN_ERR "%s: Unable to alloc disk[%d]\n", cloop_name, cloop_num); - goto error_out_free_queue; + goto error_disk; } +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) +- clo->clo_disk->queue = clo->clo_queue; +-#else +- clo->clo_disk->minors = 1; +- clo->clo_queue = clo->clo_disk->queue; +-#endif +- clo->clo_queue->queuedata = clo; +- blk_queue_max_hw_sectors(clo->clo_queue, BLK_DEF_MAX_SECTORS); - spin_lock_init(&clo->queue_lock); - mutex_init(&clo->clo_ctl_mutex); - mutex_init(&clo->clo_rq_mutex); clo->clo_disk->major = cloop_major; clo->clo_disk->first_minor = cloop_num; clo->clo_disk->fops = &clo_fops; -@@ -1163,12 +1225,8 @@ ++ clo->clo_disk->queue = clo->clo_queue; + clo->clo_disk->private_data = clo; sprintf(clo->clo_disk->disk_name, "%s%d", cloop_name, cloop_num); - add_disk(clo->clo_disk); +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +- error = add_disk(clo->clo_disk); +- if (error) +- goto error_out_free_disk; +-#endif ++ add_disk(clo->clo_disk); return 0; +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +-error_out_free_disk: +- blk_cleanup_disk(clo->clo_disk); +-#endif -error_out_free_queue: +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) +error_disk: blk_cleanup_queue(clo->clo_queue); -error_out_free_tags: +-#endif - blk_mq_free_tag_set(&clo->tag_set); -error_out_free_clo: - cloop_free(clo, sizeof(struct cloop_device)); error_out: - return -ENOMEM; +- return error; ++ return -ENOMEM; } -@@ -1179,7 +1237,6 @@ + + static void cloop_dealloc(int cloop_num) +@@ -1191,13 +1236,8 @@ + struct cloop_device *clo = cloop_dev[cloop_num]; if(clo == NULL) return; del_gendisk(clo->clo_disk); +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +- blk_cleanup_disk(clo->clo_disk); +-#else blk_cleanup_queue(clo->clo_queue); + put_disk(clo->clo_disk); +-#endif - blk_mq_free_tag_set(&clo->tag_set); - put_disk(clo->clo_disk); cloop_free(clo, sizeof(struct cloop_device)); cloop_dev[cloop_num] = NULL; + } +@@ -1286,3 +1326,8 @@ + /* The cloop init and exit function registration (especially needed for Kernel 2.6) */ + module_init(cloop_init); + module_exit(cloop_exit); ++ ++#include ++#include ++ ++MODULE_INFO(vermagic, VERMAGIC_STRING); --- cloop_suspend.c +++ cloop_suspend.c @@ -14,6 +14,7 @@ diff -r e6abe3abd527 -r c81179c4b106 linux64-cloop/stuff/cloop.u --- a/linux64-cloop/stuff/cloop.u Sat Mar 11 09:15:29 2023 +0000 +++ b/linux64-cloop/stuff/cloop.u Sat Mar 11 12:33:53 2023 +0000 @@ -327,26 +327,23 @@ xz_dec_reset(clo->xzdecoderstate); err = xz_dec_run(clo->xzdecoderstate, &clo->xz_buffer); if (err == XZ_STREAM_END || err == XZ_OK) -@@ -309,16 +304,12 @@ +@@ -309,9 +304,12 @@ while (buf_done < buf_len) { size_t size = buf_len - buf_done, size_read; -- mm_segment_t old_fs; - /* kernel_read() only supports 32 bit offsets, so we use vfs_read() instead. */ - /* int size_read = kernel_read(f, pos, buf + buf_done, size); */ -- - // mutex_lock(&clo->clo_rq_mutex); -- old_fs = get_fs(); -- set_fs(KERNEL_DS); +- size_read = kernel_read(f, buf + buf_done, size, &pos); +- // mutex_unlock(&clo->clo_rq_mutex); ++ /* kernel_read() only supports 32 bit offsets, so we use vfs_read() instead. */ ++ /* int size_read = kernel_read(f, pos, buf + buf_done, size); */ + mm_segment_t old_fs = get_fs(); + set_fs(get_ds()); - size_read = vfs_read(f, (void __user *)(buf + buf_done), size, &pos); - set_fs(old_fs); -- // mutex_unlock(&clo->clo_rq_mutex); ++ size_read = vfs_read(f, (void __user *)(buf + buf_done), size, &pos); ++ set_fs(old_fs); if(size_read <= 0) { -@@ -358,8 +349,8 @@ +@@ -351,8 +349,8 @@ return i; } @@ -357,7 +354,7 @@ /* Load one compressed block from the file. */ if(compressed_block_offset > 0 && compressed_block_len >= 0) /* sanity check */ -@@ -369,12 +360,12 @@ +@@ -362,12 +360,12 @@ if (n!= compressed_block_len) { printk(KERN_ERR "%s: error while reading %lu bytes @ %llu from file %s\n", @@ -372,7 +369,7 @@ return -1; } -@@ -382,14 +373,16 @@ +@@ -375,14 +373,16 @@ if(++clo->current_bufnum >= clo->num_buffered_blocks) clo->current_bufnum = 0; /* Do the uncompression */ @@ -392,7 +389,7 @@ clo->buffered_blocknum[clo->current_bufnum] = -1; return -1; } -@@ -397,107 +390,146 @@ +@@ -390,107 +390,146 @@ return clo->current_bufnum; } @@ -451,9 +448,7 @@ + unsigned long len = bvec.bv_len; + char *to_ptr = kmap(bvec.bv_page) + bvec.bv_offset; + while(len > 0) - { -- ret = BLK_STS_IOERR; -- break; /* invalid data, leave inner loop */ ++ { + u_int32_t length_in_buffer; + loff_t block_offset = offset; + u_int32_t offset_in_buffer; @@ -510,7 +505,9 @@ + err = wait_event_interruptible(clo->clo_event, !list_empty(&clo->clo_list) || + kthread_should_stop()); + if(unlikely(err)) -+ { + { +- ret = BLK_STS_IOERR; +- break; /* invalid data, leave inner loop */ + DEBUGP(KERN_ERR "cloop thread activated on error!? Continuing.\n"); + continue; } @@ -631,7 +628,7 @@ } /* Read header, flags and offsets from already opened file */ -@@ -508,7 +540,7 @@ +@@ -501,7 +540,7 @@ char *bbuf=NULL; unsigned int bbuf_size = 0; const unsigned int header_size = sizeof(struct cloop_head); @@ -640,7 +637,34 @@ loff_t fs_read_position = 0, header_pos[2]; int isblkdev, bytes_read, error = 0; if (clo->suspended) return error; -@@ -581,29 +613,19 @@ +@@ -521,7 +560,7 @@ + } + clo->backing_file = file; + clo->backing_inode= inode ; +- clo->underlying_total_size = (isblkdev) ? file->f_mapping->host->i_size : inode->i_size; ++ clo->underlying_total_size = (isblkdev) ? inode->i_bdev->bd_inode->i_size : inode->i_size; + if(clo->underlying_total_size < header_size) + { + printk(KERN_ERR "%s: %llu bytes (must be >= %u bytes)\n", +@@ -531,7 +570,7 @@ + } + if(isblkdev) + { +- struct request_queue *q = bdev_get_queue(I_BDEV(file->f_mapping->host)); ++ struct request_queue *q = bdev_get_queue(inode->i_bdev); + blk_queue_max_hw_sectors(clo->clo_queue, queue_max_hw_sectors(q)); /* Renamed in 2.6.34 */ + blk_queue_max_segments(clo->clo_queue, queue_max_segments(q)); /* Renamed in 2.6.34 */ + /* blk_queue_max_hw_segments(clo->clo_queue, queue_max_hw_segments(q)); */ /* Removed in 2.6.34 */ +@@ -540,7 +579,7 @@ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) + blk_queue_merge_bvec(clo->clo_queue, q->merge_bvec_fn); + #endif +- clo->underlying_blksize = block_size(I_BDEV(file->f_mapping->host)); ++ clo->underlying_blksize = block_size(inode->i_bdev); + } + else + clo->underlying_blksize = PAGE_SIZE; +@@ -574,29 +613,19 @@ goto error_release; } memcpy(&clo->head, bbuf, header_size); @@ -674,7 +698,7 @@ cloop_name, cloop_name); error=-EBADF; goto error_release; } -@@ -613,67 +635,133 @@ +@@ -606,67 +635,133 @@ cloop_name, clo->head.block_size); error=-EBADF; goto error_release; } @@ -785,13 +809,18 @@ + } + /* Read them offsets! */ + if(clo->header_first) ++ { ++ total_bytes = total_offsets * sizeof(struct block_info); ++ fs_read_position = sizeof(struct cloop_head); ++ } ++ else { - printk(KERN_ERR "%s: Bad file %s, read() %lu bytes @ %llu returned %d.\n", - cloop_name, clo->underlying_filename, (unsigned long)clo->underlying_blksize, fs_read_position, (int)bytes_read); - error=-EBADF; - goto error_release; -+ total_bytes = total_offsets * sizeof(struct block_info); -+ fs_read_position = sizeof(struct cloop_head); ++ total_bytes = total_offsets * sizeof(loff_t); ++ fs_read_position = clo->underlying_total_size - sizeof(struct cloop_head) - total_bytes; } - /* remember where to read the next blk from file */ - fs_read_position += bytes_read; @@ -800,16 +829,11 @@ - bytes_read / sizeof(loff_t)); - DEBUGP(KERN_INFO "cloop: parsing %d offsets %d to %d\n", num_readable, offsets_read, offsets_read+num_readable-1); - for (i=0,offset=0; i 0) -+ total_bytes = total_offsets * sizeof(loff_t); -+ fs_read_position = clo->underlying_total_size - sizeof(struct cloop_head) - total_bytes; -+ } -+ for(n=0;nunderlying_total_size - fs_read_position); + if(bytes_readable <= 0) break; /* Done */ @@ -847,7 +871,7 @@ clo->num_buffered_blocks = (buffers > 0 && clo->head.block_size >= 512) ? (buffers / clo->head.block_size) : 1; clo->buffered_blocknum = cloop_malloc(clo->num_buffered_blocks * sizeof (u_int32_t)); -@@ -705,36 +793,14 @@ +@@ -698,36 +793,14 @@ cloop_name, clo->largest_block); error=-ENOMEM; goto error_release_free_buffer; } @@ -889,7 +913,7 @@ if(preload > 0) { clo->preload_array_size = ((preload<=clo->head.num_blocks)?preload:clo->head.num_blocks); -@@ -780,6 +846,7 @@ +@@ -773,6 +846,7 @@ clo->preload_array_size = clo->preload_size = 0; } } @@ -897,7 +921,7 @@ /* Uncheck */ return error; error_release_free_all: -@@ -794,9 +861,13 @@ +@@ -787,9 +861,13 @@ } if (clo->buffered_blocknum) { cloop_free(clo->buffered_blocknum, sizeof(int)*clo->num_buffered_blocks); clo->buffered_blocknum=NULL; } error_release_free: @@ -912,7 +936,16 @@ if(bbuf) cloop_free(bbuf, clo->underlying_blksize); if(clo->underlying_filename) { kfree(clo->underlying_filename); clo->underlying_filename=NULL; } clo->backing_file=NULL; -@@ -829,6 +900,7 @@ +@@ -809,7 +887,7 @@ + file = fget(arg); /* get filp struct from ioctl arg fd */ + if(!file) return -EBADF; + error=cloop_set_file(cloop_num,file); +- set_disk_ro(clo->clo_disk, true); ++ set_device_ro(bdev, 1); + if(error) fput(file); + return error; + } +@@ -822,6 +900,7 @@ if(clo->refcnt > 1) /* we needed one fd for the ioctl */ return -EBUSY; if(filp==NULL) return -EINVAL; @@ -920,7 +953,7 @@ if(filp!=initial_file) fput(filp); else -@@ -839,7 +911,7 @@ +@@ -832,7 +911,7 @@ clo->backing_file = NULL; clo->backing_inode = NULL; if(clo->underlying_filename) { kfree(clo->underlying_filename); clo->underlying_filename=NULL; } @@ -929,7 +962,7 @@ if(clo->preload_cache) { int i; -@@ -1054,15 +1126,15 @@ +@@ -1047,15 +1126,15 @@ case LOOP_CLR_FD: /* Change arg */ case LOOP_GET_STATUS64: /* Change arg */ case LOOP_SET_STATUS64: /* Change arg */ @@ -949,7 +982,7 @@ } #endif -@@ -1093,7 +1165,7 @@ +@@ -1086,7 +1165,7 @@ cloop_dev[cloop_num]->refcnt-=1; } @@ -958,7 +991,7 @@ { owner: THIS_MODULE, open: cloop_open, -@@ -1105,12 +1177,6 @@ +@@ -1098,12 +1177,6 @@ /* locked_ioctl ceased to exist in 2.6.36 */ }; @@ -971,11 +1004,12 @@ static int cloop_register_blkdev(int major_nr) { return register_blkdev(major_nr, cloop_name); -@@ -1124,37 +1190,33 @@ +@@ -1117,73 +1190,45 @@ static int cloop_alloc(int cloop_num) { - struct cloop_device *clo = (struct cloop_device *) cloop_malloc(sizeof(struct cloop_device)); +- int error = -ENOMEM; + struct cloop_device *clo = (struct cloop_device *) cloop_malloc(sizeof(struct cloop_device));; if(clo == NULL) goto error_out; cloop_dev[cloop_num] = clo; @@ -990,6 +1024,7 @@ - clo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING; - clo->tag_set.driver_data = clo; - if(blk_mq_alloc_tag_set(&clo->tag_set)) goto error_out_free_clo; +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) - clo->clo_queue = blk_mq_init_queue(&clo->tag_set); - if(IS_ERR(clo->clo_queue)) + clo->clo_thread = NULL; @@ -1004,47 +1039,87 @@ - goto error_out_free_tags; + goto error_out; } - clo->clo_queue->queuedata = clo; -- blk_queue_max_hw_sectors(clo->clo_queue, BLK_DEF_MAX_SECTORS); +- clo->clo_disk = alloc_disk(1); +-#else +- clo->clo_disk = blk_mq_alloc_disk(&clo->tag_set, NULL); ++ clo->clo_queue->queuedata = clo; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, clo->clo_queue); + queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, clo->clo_queue); -+#endif - clo->clo_disk = alloc_disk(1); + #endif ++ clo->clo_disk = alloc_disk(1); if(!clo->clo_disk) { printk(KERN_ERR "%s: Unable to alloc disk[%d]\n", cloop_name, cloop_num); - goto error_out_free_queue; + goto error_disk; } +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) +- clo->clo_disk->queue = clo->clo_queue; +-#else +- clo->clo_disk->minors = 1; +- clo->clo_queue = clo->clo_disk->queue; +-#endif +- clo->clo_queue->queuedata = clo; +- blk_queue_max_hw_sectors(clo->clo_queue, BLK_DEF_MAX_SECTORS); - spin_lock_init(&clo->queue_lock); - mutex_init(&clo->clo_ctl_mutex); - mutex_init(&clo->clo_rq_mutex); clo->clo_disk->major = cloop_major; clo->clo_disk->first_minor = cloop_num; clo->clo_disk->fops = &clo_fops; -@@ -1163,12 +1225,8 @@ ++ clo->clo_disk->queue = clo->clo_queue; + clo->clo_disk->private_data = clo; sprintf(clo->clo_disk->disk_name, "%s%d", cloop_name, cloop_num); - add_disk(clo->clo_disk); +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +- error = add_disk(clo->clo_disk); +- if (error) +- goto error_out_free_disk; +-#endif ++ add_disk(clo->clo_disk); return 0; +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +-error_out_free_disk: +- blk_cleanup_disk(clo->clo_disk); +-#endif -error_out_free_queue: +-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) +error_disk: blk_cleanup_queue(clo->clo_queue); -error_out_free_tags: +-#endif - blk_mq_free_tag_set(&clo->tag_set); -error_out_free_clo: - cloop_free(clo, sizeof(struct cloop_device)); error_out: - return -ENOMEM; +- return error; ++ return -ENOMEM; } -@@ -1179,7 +1237,6 @@ + + static void cloop_dealloc(int cloop_num) +@@ -1191,13 +1236,8 @@ + struct cloop_device *clo = cloop_dev[cloop_num]; if(clo == NULL) return; del_gendisk(clo->clo_disk); +-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0) +- blk_cleanup_disk(clo->clo_disk); +-#else blk_cleanup_queue(clo->clo_queue); + put_disk(clo->clo_disk); +-#endif - blk_mq_free_tag_set(&clo->tag_set); - put_disk(clo->clo_disk); cloop_free(clo, sizeof(struct cloop_device)); cloop_dev[cloop_num] = NULL; + } +@@ -1286,3 +1326,8 @@ + /* The cloop init and exit function registration (especially needed for Kernel 2.6) */ + module_init(cloop_init); + module_exit(cloop_exit); ++ ++#include ++#include ++ ++MODULE_INFO(vermagic, VERMAGIC_STRING); --- cloop_suspend.c +++ cloop_suspend.c @@ -14,6 +14,7 @@