On Fri, 2013-02-22 at 07:43 +0800, Asias He wrote: > On 02/22/2013 06:41 AM, Nicholas A. Bellinger wrote: > > On Thu, 2013-02-21 at 15:51 +0800, Asias He wrote: > >> This patch adds support for emulation of UNMAP within > >> fd_execute_unmap() backend code. > >> > >> If the FILEIO backend is normal file, the emulation uses fallocate to > >> punch hole to reclaim the free space used by the file. If the FILEIO > >> backend is block device, the emulation uses blkdev_issue_discard(). > >> > >> TODO: fd_execute_unmap() is heavliy based on iblock_execute_unmap(). > >> Will split out and share the common code. > >> > >> Cc: Christoph Hellwig <hch@xxxxxx> > >> Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx> > >> Cc: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> > >> Signed-off-by: Asias He <asias@xxxxxxxxxx> > >> --- > >> drivers/target/target_core_file.c | 111 ++++++++++++++++++++++++++++++++++++++ > >> 1 file changed, 111 insertions(+) > >> <SNIP> > >> + if (S_ISBLK(inode->i_mode)) { > >> + /* The backend is block device, use discard */ > >> + struct block_device *bdev = inode->i_bdev; > >> + > >> + err = blkdev_issue_discard(bdev, lba, range, GFP_KERNEL, 0); > >> + if (err < 0) { > >> + pr_err("FILEIO: blkdev_issue_discard() failed: %d\n", > >> + err); > >> + ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; > >> + goto err; > >> + } > >> + } else { > >> + /* The backend is normal file, use fallocate */ > >> + loff_t pos = lba * dev->dev_attrib.block_size; > >> + unsigned int len = range * dev->dev_attrib.block_size; > >> + int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; > >> + > >> + if (!file->f_op->fallocate) { > >> + ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; > >> + goto err; > >> + } > >> + err = file->f_op->fallocate(file, mode, pos, len); > >> + if (err < 0) { > >> + pr_warn("FILEIO: fallocate() failed: %d\n", err); > >> + ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; > >> + goto err; > >> + } > >> + } > >> + > > > > Moving the if (S_ISBLK(inode->i_mode) { .. } else { .. } blocks into a > > separate function that can be shared by fd_execute_write_same_unmap() > > would save a few LOC here. > > Yes, exactly. Also we only need !file->f_op->fallocate check once. > > BTW, which file is the best place to put common code for > fd_execute_unmap() and iblock_execute_unmap(). > Common code for unmap emulation can go into target_core_sbc.c -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html