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
This commit is contained in:
Billy Olsen 2017-03-08 17:18:11 -07:00
parent 0142d5045a
commit 857a00c65b
1 changed files with 11 additions and 42 deletions

View File

@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from _ctypes import POINTER, byref
import ctypes
import collections
import json
@ -321,52 +320,22 @@ def set_hdd_read_ahead(dev_name, read_ahead_sectors=256):
def get_block_uuid(block_dev):
"""
This queries blkid to get the uuid for a block device. Note: This function
needs to be called with root priv. It will raise an error otherwise.
This queries blkid to get the uuid for a block device.
:param block_dev: Name of the block device to query.
:return: The UUID of the device or None on Error. Raises OSError
:return: The UUID of the device or None on Error.
"""
try:
blkid = ctypes.cdll.LoadLibrary("libblkid.so")
# Header signature
# extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
# const char **data, size_t *len);
blkid.blkid_new_probe_from_filename.argtypes = [ctypes.c_char_p]
blkid.blkid_probe_lookup_value.argtypes = [ctypes.c_void_p,
ctypes.c_char_p,
POINTER(ctypes.c_char_p),
POINTER(ctypes.c_ulong)]
except OSError as err:
log('get_block_uuid loading libblkid.so failed with error: {}'.format(
os.strerror(err.errno)),
level=ERROR)
raise err
if not os.path.exists(block_dev):
block_info = subprocess.check_output(
['blkid', '-o', 'export', block_dev])
for tag in block_info.split('\n'):
parts = tag.split('=')
if parts[0] == 'UUID':
return parts[1]
return None
probe = blkid.blkid_new_probe_from_filename(ctypes.c_char_p(block_dev))
if probe < 0:
log('get_block_uuid new_probe_from_filename failed: {}'.format(
os.strerror(probe)),
except subprocess.CalledProcessError as err:
log('get_block_uuid failed with error: {}'.format(err.output),
level=ERROR)
raise OSError(probe, os.strerror(probe))
result = blkid.blkid_do_probe(probe)
if result != 0:
log('get_block_uuid do_probe failed with error: {}'.format(
os.strerror(result)),
level=ERROR)
raise OSError(result, os.strerror(result))
uuid = ctypes.c_char_p()
result = blkid.blkid_probe_lookup_value(probe,
ctypes.c_char_p(
'UUID'.encode('ascii')),
byref(uuid), None)
if result < 0:
log('get_block_uuid lookup_value failed with error: {}'.format(
os.strerror(result)),
level=ERROR)
raise OSError(result, os.strerror(result))
blkid.blkid_free_probe(probe)
return ctypes.string_at(uuid).decode('ascii')
return None
def check_max_sectors(save_settings_dict,