@@ -79,6 +79,7 @@ func (m *mounter) GetBlockSizeBytes(devicePath string) (int64, error) {
7979}
8080
8181func (m * mounter ) GetDevicePath (ctx context.Context , volumeID string ) (string , error ) {
82+ logger := klog .FromContext (ctx )
8283 backoff := wait.Backoff {
8384 Duration : 2 * time .Second ,
8485 Factor : 1.5 ,
@@ -87,13 +88,13 @@ func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, e
8788
8889 var devicePath string
8990 err := wait .ExponentialBackoffWithContext (ctx , backoff , func (context.Context ) (bool , error ) {
90- path , err := m .getDevicePathBySerialID (volumeID )
91+ path , err := m .getDevicePathBySerialID (ctx , volumeID )
9192 if err != nil {
9293 return false , err
9394 }
9495 if path != "" {
9596 devicePath = path
96-
97+ logger . V ( 4 ). Info ( "Device path found" , "volumeID" , volumeID , "devicePath" , path )
9798 return true , nil
9899 }
99100 m .probeVolume (ctx )
@@ -110,20 +111,22 @@ func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, e
110111 return devicePath , nil
111112}
112113
113- func (m * mounter ) getDevicePathBySerialID (volumeID string ) (string , error ) {
114+ func (m * mounter ) getDevicePathBySerialID (ctx context.Context , volumeID string ) (string , error ) {
115+ logger := klog .FromContext (ctx )
116+
114117 // First try XenServer device paths
115- xenDevicePath , err := m .getDevicePathForXenServer (volumeID )
118+ xenDevicePath , err := m .getDevicePathForXenServer (ctx , volumeID )
116119 if err != nil {
117- fmt . Printf ( "Failed to get XenServer device path: %v \n " , err )
120+ logger . V ( 4 ). Info ( "Failed to get XenServer device path" , "volumeID" , volumeID , "error " , err )
118121 }
119122 if xenDevicePath != "" {
120123 return xenDevicePath , nil
121124 }
122125
123126 // Try VMware device paths
124- vmwareDevicePath , err := m .getDevicePathForVMware (volumeID )
127+ vmwareDevicePath , err := m .getDevicePathForVMware (ctx , volumeID )
125128 if err != nil {
126- fmt . Printf ( "Failed to get VMware device path: %v \n " , err )
129+ logger . V ( 4 ). Info ( "Failed to get VMware device path" , "volumeID" , volumeID , "error " , err )
127130 }
128131 if vmwareDevicePath != "" {
129132 return vmwareDevicePath , nil
@@ -146,16 +149,18 @@ func (m *mounter) getDevicePathBySerialID(volumeID string) (string, error) {
146149 return "" , nil
147150}
148151
149- func (m * mounter ) getDevicePathForXenServer (volumeID string ) (string , error ) {
152+ func (m * mounter ) getDevicePathForXenServer (ctx context.Context , volumeID string ) (string , error ) {
153+ logger := klog .FromContext (ctx )
154+
150155 for i := 'b' ; i <= 'z' ; i ++ {
151156 devicePath := fmt .Sprintf ("/dev/xvd%c" , i )
152- fmt . Printf ( "Checking XenServer device path: %s \n " , devicePath )
157+ logger . V ( 5 ). Info ( "Checking XenServer device path" , "devicePath" , devicePath , "volumeID" , volumeID )
153158
154159 if _ , err := os .Stat (devicePath ); err == nil {
155160 isBlock , err := m .IsBlockDevice (devicePath )
156161 if err == nil && isBlock {
157- if m .verifyXenServerDevice ( devicePath , volumeID ) {
158- fmt . Printf ( "Found and verified XenServer device: %s \n " , devicePath )
162+ if m .verifyDevice ( ctx , devicePath , volumeID ) {
163+ logger . V ( 4 ). Info ( "Found and verified XenServer device" , "devicePath" , devicePath , "volumeID" , volumeID )
159164 return devicePath , nil
160165 }
161166 }
@@ -164,46 +169,19 @@ func (m *mounter) getDevicePathForXenServer(volumeID string) (string, error) {
164169 return "" , fmt .Errorf ("device not found for volume %s" , volumeID )
165170}
166171
167- func (m * mounter ) verifyXenServerDevice (devicePath string , volumeID string ) bool {
168- size , err := m .GetBlockSizeBytes (devicePath )
169- if err != nil {
170- fmt .Printf ("Failed to get device size: %v\n " , err )
171- return false
172- }
173- fmt .Printf ("Device size: %d bytes\n " , size )
174-
175- mounted , err := m .isDeviceMounted (devicePath )
176- if err != nil {
177- fmt .Printf ("Failed to check if device is mounted: %v\n " , err )
178- return false
179- }
180- if mounted {
181- fmt .Printf ("Device is already mounted: %s\n " , devicePath )
182- return false
183- }
184-
185- props , err := m .getDeviceProperties (devicePath )
186- if err != nil {
187- fmt .Printf ("Failed to get device properties: %v\n " , err )
188- return false
189- }
190- fmt .Printf ("Device properties: %v\n " , props )
191-
192- return true
193- }
172+ func (m * mounter ) getDevicePathForVMware (ctx context.Context , volumeID string ) (string , error ) {
173+ logger := klog .FromContext (ctx )
194174
195- func (m * mounter ) getDevicePathForVMware (volumeID string ) (string , error ) {
196175 // Loop through /dev/sdb to /dev/sdz (/dev/sda -> the root disk)
197176 for i := 'b' ; i <= 'z' ; i ++ {
198177 devicePath := fmt .Sprintf ("/dev/sd%c" , i )
199- fmt . Printf ( "Checking VMware device path: %s \n " , devicePath )
178+ logger . V ( 5 ). Info ( "Checking VMware device path" , "devicePath" , devicePath , "volumeID" , volumeID )
200179
201180 if _ , err := os .Stat (devicePath ); err == nil {
202181 isBlock , err := m .IsBlockDevice (devicePath )
203182 if err == nil && isBlock {
204- // Use the same verification as for XenServer
205- if m .verifyVMwareDevice (devicePath , volumeID ) {
206- fmt .Printf ("Found and verified VMware device: %s\n " , devicePath )
183+ if m .verifyDevice (ctx , devicePath , volumeID ) {
184+ logger .V (4 ).Info ("Found and verified VMware device" , "devicePath" , devicePath , "volumeID" , volumeID )
207185 return devicePath , nil
208186 }
209187 }
@@ -212,30 +190,32 @@ func (m *mounter) getDevicePathForVMware(volumeID string) (string, error) {
212190 return "" , fmt .Errorf ("device not found for volume %s" , volumeID )
213191}
214192
215- func (m * mounter ) verifyVMwareDevice (devicePath string , volumeID string ) bool {
193+ func (m * mounter ) verifyDevice (ctx context.Context , devicePath string , volumeID string ) bool {
194+ logger := klog .FromContext (ctx )
195+
216196 size , err := m .GetBlockSizeBytes (devicePath )
217197 if err != nil {
218- fmt . Printf ( "Failed to get device size: %v \n " , err )
198+ logger . V ( 4 ). Info ( "Failed to get device size" , "devicePath" , devicePath , "volumeID" , volumeID , "error " , err )
219199 return false
220200 }
221- fmt . Printf ( "Device size: %d bytes \n " , size )
201+ logger . V ( 5 ). Info ( "Device size retrieved" , "devicePath" , devicePath , "volumeID" , volumeID , "sizeBytes " , size )
222202
223203 mounted , err := m .isDeviceMounted (devicePath )
224204 if err != nil {
225- fmt . Printf ( "Failed to check if device is mounted: %v \n " , err )
205+ logger . V ( 4 ). Info ( "Failed to check if device is mounted" , "devicePath" , devicePath , "volumeID" , volumeID , "error " , err )
226206 return false
227207 }
228208 if mounted {
229- fmt . Printf ( "Device is already mounted: %s \n " , devicePath )
209+ logger . V ( 4 ). Info ( "Device is already mounted" , "devicePath" , devicePath , "volumeID" , volumeID )
230210 return false
231211 }
232212
233213 props , err := m .getDeviceProperties (devicePath )
234214 if err != nil {
235- fmt . Printf ( "Failed to get device properties: %v \n " , err )
215+ logger . V ( 4 ). Info ( "Failed to get device properties" , "devicePath" , devicePath , "volumeID" , volumeID , "error " , err )
236216 return false
237217 }
238- fmt . Printf ( "Device properties: %v \n " , props )
218+ logger . V ( 5 ). Info ( "Device properties retrieved" , "devicePath" , devicePath , "volumeID" , volumeID , "properties " , props )
239219
240220 return true
241221}
0 commit comments