@@ -86,6 +86,24 @@ static struct se_device *fd_alloc_device(struct se_hba *hba, const char *name)
8686 return & fd_dev -> dev ;
8787}
8888
89+ static bool fd_configure_unmap (struct se_device * dev )
90+ {
91+ struct file * file = FD_DEV (dev )-> fd_file ;
92+ struct inode * inode = file -> f_mapping -> host ;
93+
94+ if (S_ISBLK (inode -> i_mode ))
95+ return target_configure_unmap_from_queue (& dev -> dev_attrib ,
96+ I_BDEV (inode ));
97+
98+ /* Limit UNMAP emulation to 8k Number of LBAs (NoLB) */
99+ dev -> dev_attrib .max_unmap_lba_count = 0x2000 ;
100+ /* Currently hardcoded to 1 in Linux/SCSI code. */
101+ dev -> dev_attrib .max_unmap_block_desc_count = 1 ;
102+ dev -> dev_attrib .unmap_granularity = 1 ;
103+ dev -> dev_attrib .unmap_granularity_alignment = 0 ;
104+ return true;
105+ }
106+
89107static int fd_configure_device (struct se_device * dev )
90108{
91109 struct fd_dev * fd_dev = FD_DEV (dev );
@@ -149,10 +167,6 @@ static int fd_configure_device(struct se_device *dev)
149167 " block_device blocks: %llu logical_block_size: %d\n" ,
150168 dev_size , div_u64 (dev_size , fd_dev -> fd_block_size ),
151169 fd_dev -> fd_block_size );
152-
153- if (target_configure_unmap_from_queue (& dev -> dev_attrib , bdev ))
154- pr_debug ("IFILE: BLOCK Discard support available,"
155- " disabled by default\n" );
156170 /*
157171 * Enable write same emulation for IBLOCK and use 0xFFFF as
158172 * the smaller WRITE_SAME(10) only has a two-byte block count.
@@ -170,16 +184,6 @@ static int fd_configure_device(struct se_device *dev)
170184 }
171185
172186 fd_dev -> fd_block_size = FD_BLOCKSIZE ;
173- /*
174- * Limit UNMAP emulation to 8k Number of LBAs (NoLB)
175- */
176- dev -> dev_attrib .max_unmap_lba_count = 0x2000 ;
177- /*
178- * Currently hardcoded to 1 in Linux/SCSI code..
179- */
180- dev -> dev_attrib .max_unmap_block_desc_count = 1 ;
181- dev -> dev_attrib .unmap_granularity = 1 ;
182- dev -> dev_attrib .unmap_granularity_alignment = 0 ;
183187
184188 /*
185189 * Limit WRITE_SAME w/ UNMAP=0 emulation to 8k Number of LBAs (NoLB)
@@ -920,6 +924,7 @@ static const struct target_backend_ops fileio_ops = {
920924 .configure_device = fd_configure_device ,
921925 .destroy_device = fd_destroy_device ,
922926 .free_device = fd_free_device ,
927+ .configure_unmap = fd_configure_unmap ,
923928 .parse_cdb = fd_parse_cdb ,
924929 .set_configfs_dev_params = fd_set_configfs_dev_params ,
925930 .show_configfs_dev_params = fd_show_configfs_dev_params ,
0 commit comments