Browse Source

Revert "Use libblkid instead of CLI"

This reverts commit a7f29e52ef
which switched to using libblkid instead of invoking the blkid
command on the commandline.

The replacement code introduced as part of that commit does not
actually fix the bug that it was intended to fix and only adds
unnecessary complexity to the code. The bug is being tagged
by this commit message to help identify the full set of fixes
for the actual bug.

Change-Id: I21b32197c8db4a3c667c986180cdd213fced2c26
Related-Bug: #1660240
Billy Olsen 2 years ago
parent
commit
857a00c65b
1 changed files with 11 additions and 42 deletions
  1. 11
    42
      ceph/__init__.py

+ 11
- 42
ceph/__init__.py View File

@@ -11,7 +11,6 @@
11 11
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14
-from _ctypes import POINTER, byref
15 14
 import ctypes
16 15
 import collections
17 16
 import json
@@ -321,52 +320,22 @@ def set_hdd_read_ahead(dev_name, read_ahead_sectors=256):
321 320
 
322 321
 def get_block_uuid(block_dev):
323 322
     """
324
-    This queries blkid to get the uuid for a block device. Note: This function
325
-    needs to be called with root priv.  It will raise an error otherwise.
323
+    This queries blkid to get the uuid for a block device.
326 324
     :param block_dev: Name of the block device to query.
327
-    :return: The UUID of the device or None on Error. Raises OSError
325
+    :return: The UUID of the device or None on Error.
328 326
     """
329 327
     try:
330
-        blkid = ctypes.cdll.LoadLibrary("libblkid.so")
331
-        # Header signature
332
-        # extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
333
-        #                                     const char **data, size_t *len);
334
-        blkid.blkid_new_probe_from_filename.argtypes = [ctypes.c_char_p]
335
-        blkid.blkid_probe_lookup_value.argtypes = [ctypes.c_void_p,
336
-                                                   ctypes.c_char_p,
337
-                                                   POINTER(ctypes.c_char_p),
338
-                                                   POINTER(ctypes.c_ulong)]
339
-    except OSError as err:
340
-        log('get_block_uuid loading libblkid.so failed with error: {}'.format(
341
-            os.strerror(err.errno)),
342
-            level=ERROR)
343
-        raise err
344
-    if not os.path.exists(block_dev):
328
+        block_info = subprocess.check_output(
329
+            ['blkid', '-o', 'export', block_dev])
330
+        for tag in block_info.split('\n'):
331
+            parts = tag.split('=')
332
+            if parts[0] == 'UUID':
333
+                return parts[1]
345 334
         return None
346
-    probe = blkid.blkid_new_probe_from_filename(ctypes.c_char_p(block_dev))
347
-    if probe < 0:
348
-        log('get_block_uuid new_probe_from_filename failed: {}'.format(
349
-            os.strerror(probe)),
350
-            level=ERROR)
351
-        raise OSError(probe, os.strerror(probe))
352
-    result = blkid.blkid_do_probe(probe)
353
-    if result != 0:
354
-        log('get_block_uuid do_probe failed with error: {}'.format(
355
-            os.strerror(result)),
356
-            level=ERROR)
357
-        raise OSError(result, os.strerror(result))
358
-    uuid = ctypes.c_char_p()
359
-    result = blkid.blkid_probe_lookup_value(probe,
360
-                                            ctypes.c_char_p(
361
-                                                'UUID'.encode('ascii')),
362
-                                            byref(uuid), None)
363
-    if result < 0:
364
-        log('get_block_uuid lookup_value failed with error: {}'.format(
365
-            os.strerror(result)),
335
+    except subprocess.CalledProcessError as err:
336
+        log('get_block_uuid failed with error: {}'.format(err.output),
366 337
             level=ERROR)
367
-        raise OSError(result, os.strerror(result))
368
-    blkid.blkid_free_probe(probe)
369
-    return ctypes.string_at(uuid).decode('ascii')
338
+        return None
370 339
 
371 340
 
372 341
 def check_max_sectors(save_settings_dict,

Loading…
Cancel
Save