33 * Description: uring_cmd based ublk
44 */
55
6+ #include <linux/fs.h>
67#include "kublk.h"
78
89#define MAX_NR_TGT_ARG 64
@@ -1550,6 +1551,8 @@ static void __cmd_create_help(char *exe, bool recovery)
15501551 printf ("\t[--foreground] [--quiet] [-z] [--auto_zc] [--auto_zc_fallback] [--debug_mask mask] [-r 0|1] [-g] [-u]\n" );
15511552 printf ("\t[-e 0|1 ] [-i 0|1] [--no_ublk_fixed_fd]\n" );
15521553 printf ("\t[--nthreads threads] [--per_io_tasks]\n" );
1554+ printf ("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
1555+ "[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n" );
15531556 printf ("\t[target options] [backfile1] [backfile2] ...\n" );
15541557 printf ("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n" );
15551558 printf ("\tdefault: nthreads=nr_queues" );
@@ -1613,6 +1616,12 @@ int main(int argc, char *argv[])
16131616 { "nthreads" , 1 , NULL , 0 },
16141617 { "per_io_tasks" , 0 , NULL , 0 },
16151618 { "no_ublk_fixed_fd" , 0 , NULL , 0 },
1619+ { "integrity_capable" , 0 , NULL , 0 },
1620+ { "integrity_reftag" , 0 , NULL , 0 },
1621+ { "metadata_size" , 1 , NULL , 0 },
1622+ { "pi_offset" , 1 , NULL , 0 },
1623+ { "csum_type" , 1 , NULL , 0 },
1624+ { "tag_size" , 1 , NULL , 0 },
16161625 { 0 , 0 , 0 , 0 }
16171626 };
16181627 const struct ublk_tgt_ops * ops = NULL ;
@@ -1623,6 +1632,7 @@ int main(int argc, char *argv[])
16231632 .nr_hw_queues = 2 ,
16241633 .dev_id = -1 ,
16251634 .tgt_type = "unknown" ,
1635+ .csum_type = LBMD_PI_CSUM_NONE ,
16261636 };
16271637 int ret = - EINVAL , i ;
16281638 int tgt_argc = 1 ;
@@ -1697,6 +1707,28 @@ int main(int argc, char *argv[])
16971707 ctx .per_io_tasks = 1 ;
16981708 if (!strcmp (longopts [option_idx ].name , "no_ublk_fixed_fd" ))
16991709 ctx .no_ublk_fixed_fd = 1 ;
1710+ if (!strcmp (longopts [option_idx ].name , "integrity_capable" ))
1711+ ctx .integrity_flags |= LBMD_PI_CAP_INTEGRITY ;
1712+ if (!strcmp (longopts [option_idx ].name , "integrity_reftag" ))
1713+ ctx .integrity_flags |= LBMD_PI_CAP_REFTAG ;
1714+ if (!strcmp (longopts [option_idx ].name , "metadata_size" ))
1715+ ctx .metadata_size = strtoul (optarg , NULL , 0 );
1716+ if (!strcmp (longopts [option_idx ].name , "pi_offset" ))
1717+ ctx .pi_offset = strtoul (optarg , NULL , 0 );
1718+ if (!strcmp (longopts [option_idx ].name , "csum_type" )) {
1719+ if (!strcmp (optarg , "ip" )) {
1720+ ctx .csum_type = LBMD_PI_CSUM_IP ;
1721+ } else if (!strcmp (optarg , "t10dif" )) {
1722+ ctx .csum_type = LBMD_PI_CSUM_CRC16_T10DIF ;
1723+ } else if (!strcmp (optarg , "nvme" )) {
1724+ ctx .csum_type = LBMD_PI_CSUM_CRC64_NVME ;
1725+ } else {
1726+ ublk_err ("invalid csum_type: %s\n" , optarg );
1727+ return - EINVAL ;
1728+ }
1729+ }
1730+ if (!strcmp (longopts [option_idx ].name , "tag_size" ))
1731+ ctx .tag_size = strtoul (optarg , NULL , 0 );
17001732 break ;
17011733 case '?' :
17021734 /*
@@ -1739,6 +1771,21 @@ int main(int argc, char *argv[])
17391771 return - EINVAL ;
17401772 }
17411773
1774+ if (ctx .metadata_size ) {
1775+ if (!(ctx .flags & UBLK_F_USER_COPY )) {
1776+ ublk_err ("integrity requires user_copy\n" );
1777+ return - EINVAL ;
1778+ }
1779+
1780+ ctx .flags |= UBLK_F_INTEGRITY ;
1781+ } else if (ctx .integrity_flags ||
1782+ ctx .pi_offset ||
1783+ ctx .csum_type != LBMD_PI_CSUM_NONE ||
1784+ ctx .tag_size ) {
1785+ ublk_err ("integrity parameters require metadata_size\n" );
1786+ return - EINVAL ;
1787+ }
1788+
17421789 i = optind ;
17431790 while (i < argc && ctx .nr_files < MAX_BACK_FILES ) {
17441791 ctx .files [ctx .nr_files ++ ] = argv [i ++ ];
0 commit comments