@@ -39,33 +39,6 @@ def setUp(self):
3939 self .mcl = to_decimal (self .get_id_ns_field_value ("mcl" ))
4040 self .mssrl = to_decimal (self .get_id_ns_field_value ("mssrl" ))
4141 self .msrc = to_decimal (self .get_id_ns_field_value ("msrc" ))
42- cross_namespace_copy = self .ocfs & 0xc
43- if cross_namespace_copy :
44- get_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
45- f"{ self .ctrl } --output-format=json"
46- result = self .run_cmd (get_features_cmd )
47- self .assertEqual (result .returncode , 0 ,
48- "ERROR : nvme feat host-behavior-support failed" )
49- data = json .loads (result .stdout )
50- fields = data .get ("Feature: 0x16" , [{}])[0 ]
51- # reconstruct cdfe from individual CDF bit fields
52- current_cdfe = (
53- (0x4 if fields .get ("Copy Descriptor Format 2h Enable (CDF2E)" ) == "True" else 0 ) |
54- (0x8 if fields .get ("Copy Descriptor Format 3h Enable (CDF3E)" ) == "True" else 0 ) |
55- (0x10 if fields .get ("Copy Descriptor Format 4h Enable (CDF4E)" ) == "True" else 0 )
56- )
57- if current_cdfe & cross_namespace_copy :
58- # skip if already enabled
59- print ("Cross-namespace copy already enabled, skipping set-features" )
60- else :
61- # save original cdfe for restore on teardown
62- self .original_cdfe = current_cdfe
63- new_cdfe = current_cdfe | cross_namespace_copy
64- set_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
65- f"{ self .ctrl } --cdfe={ new_cdfe } "
66- result = self .run_cmd (set_features_cmd )
67- self .assertEqual (result .returncode , 0 ,
68- "Failed to enable cross-namespace copy formats" )
6942 get_ns_id_cmd = f"{ self .nvme_bin } get-ns-id { self .ns1 } "
7043 result = self .run_cmd (get_ns_id_cmd )
7144 err = result .returncode
@@ -96,6 +69,38 @@ def _check_ns_copy_limits(self):
9669 if missing :
9770 self .skipTest (f"{ ', ' .join (missing )} are 0, copy not supported on this namespace" )
9871
72+ def _enable_cdfe_for_format (self , desc_format ):
73+ """ Enable the host-behavior-support cdfe bit for the given cross-namespace format.
74+ Only the bit corresponding to desc_format is enabled; other bits are left unchanged.
75+ The original value is saved in self.original_cdfe for tearDown to restore.
76+ """
77+ cdfe_bit = 1 << desc_format
78+ get_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
79+ f"{ self .ctrl } --output-format=json"
80+ result = self .run_cmd (get_features_cmd )
81+ self .assertEqual (result .returncode , 0 ,
82+ "ERROR : nvme feat host-behavior-support failed" )
83+ data = json .loads (result .stdout )
84+ fields = data .get ("Feature: 0x16" , [{}])[0 ]
85+ # reconstruct cdfe from individual CDF bit fields
86+ current_cdfe = (
87+ (0x4 if fields .get ("Copy Descriptor Format 2h Enable (CDF2E)" ) == "True" else 0 ) |
88+ (0x8 if fields .get ("Copy Descriptor Format 3h Enable (CDF3E)" ) == "True" else 0 ) |
89+ (0x10 if fields .get ("Copy Descriptor Format 4h Enable (CDF4E)" ) == "True" else 0 )
90+ )
91+ if current_cdfe & cdfe_bit :
92+ # the required bit is already enabled, nothing to do
93+ return
94+ # save original cdfe for restore in tearDown (only save once)
95+ if self .original_cdfe is None :
96+ self .original_cdfe = current_cdfe
97+ new_cdfe = current_cdfe | cdfe_bit
98+ set_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
99+ f"{ self .ctrl } --cdfe={ new_cdfe } "
100+ result = self .run_cmd (set_features_cmd )
101+ self .assertEqual (result .returncode , 0 ,
102+ f"Failed to enable cdfe bit { cdfe_bit :#x} for format { desc_format } " )
103+
99104 def copy (self , sdlba , blocks , slbs , ** kwargs ):
100105 """ Wrapper for nvme copy
101106 - Args:
@@ -136,22 +141,26 @@ def test_copy_format_2(self):
136141 """ Test copy with descriptor format 2 """
137142 self ._check_format_supported (2 )
138143 self ._check_ns_copy_limits ()
144+ self ._enable_cdfe_for_format (2 )
139145 self .copy (0 , 1 , 2 , descriptor_format = 2 , snsids = self .ns1_nsid )
140146
141147 def test_copy_format_2_sopts (self ):
142148 """ Test copy with descriptor format 2 and source options """
143149 self ._check_format_supported (2 )
144150 self ._check_ns_copy_limits ()
151+ self ._enable_cdfe_for_format (2 )
145152 self .copy (0 , 1 , 2 , descriptor_format = 2 , snsids = self .ns1_nsid , sopts = 0 )
146153
147154 def test_copy_format_3 (self ):
148155 """ Test copy with descriptor format 3 """
149156 self ._check_format_supported (3 )
150157 self ._check_ns_copy_limits ()
158+ self ._enable_cdfe_for_format (3 )
151159 self .copy (0 , 1 , 2 , descriptor_format = 3 , snsids = self .ns1_nsid )
152160
153161 def test_copy_format_3_sopts (self ):
154162 """ Test copy with descriptor format 3 and source options """
155163 self ._check_format_supported (3 )
156164 self ._check_ns_copy_limits ()
165+ self ._enable_cdfe_for_format (3 )
157166 self .copy (0 , 1 , 2 , descriptor_format = 3 , snsids = self .ns1_nsid , sopts = 0 )
0 commit comments