From f64d742e4f1ac64914975284817fd734c0f4b7f3 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Fri, 10 Oct 2014 10:23:34 +0200 Subject: [PATCH] ceph-disk: encapsulate partprobe / partx calls Add the update_partition function to reduce code duplication. The action is made an argument although it always is -a because it will be -d when deleting a partition. Use the update_partition function in prepare_journal_dev Signed-off-by: Loic Dachary (cherry picked from commit 922a15ea6865ef915bbdec2597433da6792c1cb2) Conflicts: src/ceph-disk --- src/ceph-disk | 57 +++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index 44e4dd7cff865..b4fc41456125a 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -896,6 +896,35 @@ def get_free_partition_index(dev): return num +def update_partition(action, dev, description): + # try to make sure the kernel refreshes the table. note + # that if this gets ebusy, we are probably racing with + # udev because it already updated it.. ignore failure here. + + # On RHEL and CentOS distros, calling partprobe forces a reboot of the + # server. Since we are not resizing partitons so we rely on calling + # partx + if platform_distro().startswith(('centos', 'red', 'scientific')): + LOG.info('calling partx on %s device %s', description, dev) + LOG.info('re-reading known partitions will display errors') + command( + [ + 'partx', + action, + dev, + ], + ) + + else: + LOG.debug('Calling partprobe on %s device %s', description, dev) + command( + [ + 'partprobe', + dev, + ], + ) + + def zap(dev): """ Destroy the partition table and content of a given disk. @@ -987,32 +1016,7 @@ def prepare_journal_dev( ], ) - # try to make sure the kernel refreshes the table. note - # that if this gets ebusy, we are probably racing with - # udev because it already updated it.. ignore failure here. - - # On RHEL and CentOS distros, calling partprobe forces a reboot of the - # server. Since we are not resizing partitons so we rely on calling - # partx - if platform_distro().startswith(('centos', 'red')): - LOG.info('calling partx on prepared device %s', journal) - LOG.info('re-reading known partitions will display errors') - command( - [ - 'partx', - '-a', - journal, - ], - ) - - else: - LOG.debug('Calling partprobe on prepared device %s', journal) - command( - [ - 'partprobe', - journal, - ], - ) + update_partition('-a', journal, 'prepared') # wait for udev event queue to clear command( @@ -1037,7 +1041,6 @@ def prepare_journal_dev( except subprocess.CalledProcessError as e: raise Error(e) - def prepare_journal_file( journal): -- 2.39.5