1616
1717"""
1818
19- import base64
19+ import json
2020
2121from nvme_test import TestNVMe
2222
@@ -27,35 +27,39 @@ class TestNVMeCopy(TestNVMe):
2727 Represents NVMe Copy testcase.
2828 - Attributes:
2929 - ocfs : optional copy formats supported
30- - host_behavior_data : host behavior support data to restore during teardown
30+ - original_cdfe : saved cdfe value to restore during teardown, or None
3131 - test_log_dir : directory for logs, temp files.
3232 """
3333
3434 def setUp (self ):
3535 """ Pre Section for TestNVMeCopy """
3636 super ().setUp ()
3737 self .ocfs = self .get_ocfs ()
38- self .host_behavior_data = None
38+ self .original_cdfe = None
3939 cross_namespace_copy = self .ocfs & 0xc
4040 if cross_namespace_copy :
41- # get host behavior support data
42- get_features_cmd = f"{ self .nvme_bin } get-feature { self .ctrl } " + \
43- "--feature-id=0x16 --data-len=512 --raw-binary"
41+ get_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
42+ f"{ self .ctrl } --output-format=json"
4443 result = self .run_cmd (get_features_cmd )
45- err = result .returncode
46- self .assertEqual (err , 0 , "ERROR : nvme get-feature failed" )
47- self .host_behavior_data = result .stdout
48- # enable cross-namespace copy formats
49- if int .from_bytes (base64 .b64decode (self .host_behavior_data [4 ])) & cross_namespace_copy :
50- # skip if already enabled
44+ self .assertEqual (result .returncode , 0 ,
45+ "ERROR : nvme feat host-behavior-support failed" )
46+ data = json .loads (result .stdout )
47+ fields = data .get ("Feature: 0x16" , [{}])[0 ]
48+ current_cdfe = (
49+ (0x4 if fields .get ("Copy Descriptor Format 2h Enable (CDF2E)" ) == "True" else 0 ) |
50+ (0x8 if fields .get ("Copy Descriptor Format 3h Enable (CDF3E)" ) == "True" else 0 ) |
51+ (0x10 if fields .get ("Copy Descriptor Format 4h Enable (CDF4E)" ) == "True" else 0 )
52+ )
53+ if current_cdfe & cross_namespace_copy :
5154 print ("Cross-namespace copy already enabled, skipping set-features" )
52- self .host_behavior_data = None
5355 else :
54- data = self .host_behavior_data [:4 ] + str (cross_namespace_copy .to_bytes (2 , 'little' )) + self .host_behavior_data [6 :]
55- set_features_cmd = f"{ self .nvme_bin } set-feature " + \
56- f"{ self .ctrl } --feature-id=0x16 --data-len=512"
57- result = self .run_cmd (set_features_cmd , stdin_data = data )
58- self .assertEqual (result .returncode , 0 , "Failed to enable cross-namespace copy formats" )
56+ self .original_cdfe = current_cdfe
57+ new_cdfe = current_cdfe | cross_namespace_copy
58+ set_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
59+ f"{ self .ctrl } --cdfe={ new_cdfe } "
60+ result = self .run_cmd (set_features_cmd )
61+ self .assertEqual (result .returncode , 0 ,
62+ "Failed to enable cross-namespace copy formats" )
5963 get_ns_id_cmd = f"{ self .nvme_bin } get-ns-id { self .ns1 } "
6064 result = self .run_cmd (get_ns_id_cmd )
6165 err = result .returncode
@@ -66,11 +70,10 @@ def setUp(self):
6670
6771 def tearDown (self ):
6872 """ Post Section for TestNVMeCopy """
69- if self .host_behavior_data :
70- # restore saved host behavior support data
71- set_features_cmd = f"{ self .nvme_bin } set-feature { self .ctrl } " + \
72- "--feature-id=0x16 --data-len=512"
73- self .run_cmd (set_features_cmd , stdin_data = self .host_behavior_data )
73+ if self .original_cdfe is not None :
74+ set_features_cmd = f"{ self .nvme_bin } feat host-behavior-support " + \
75+ f"{ self .ctrl } --cdfe={ self .original_cdfe } "
76+ self .run_cmd (set_features_cmd )
7477 super ().tearDown ()
7578
7679 def copy (self , sdlba , blocks , slbs , ** kwargs ):
0 commit comments