Revision 7fe23d47 lib/bdev.py
b/lib/bdev.py | ||
---|---|---|
331 | 331 |
for child in self._children: |
332 | 332 |
child.SetInfo(text) |
333 | 333 |
|
334 |
def Grow(self, amount): |
|
334 |
def Grow(self, amount, dryrun):
|
|
335 | 335 |
"""Grow the block device. |
336 | 336 |
|
337 |
@type amount: integer |
|
337 | 338 |
@param amount: the amount (in mebibytes) to grow with |
339 |
@type dryrun: boolean |
|
340 |
@param dryrun: whether to execute the operation in simulation mode |
|
341 |
only, without actually increasing the size |
|
338 | 342 |
|
339 | 343 |
""" |
340 | 344 |
raise NotImplementedError |
... | ... | |
753 | 757 |
_ThrowError("Command: %s error: %s - %s", result.cmd, result.fail_reason, |
754 | 758 |
result.output) |
755 | 759 |
|
756 |
def Grow(self, amount): |
|
760 |
def Grow(self, amount, dryrun):
|
|
757 | 761 |
"""Grow the logical volume. |
758 | 762 |
|
759 | 763 |
""" |
... | ... | |
764 | 768 |
rest = amount % full_stripe_size |
765 | 769 |
if rest != 0: |
766 | 770 |
amount += full_stripe_size - rest |
771 |
cmd = ["lvextend", "-L", "+%dm" % amount] |
|
772 |
if dryrun: |
|
773 |
cmd.append("--test") |
|
767 | 774 |
# we try multiple algorithms since the 'best' ones might not have |
768 | 775 |
# space available in the right place, but later ones might (since |
769 | 776 |
# they have less constraints); also note that only recent LVM |
770 | 777 |
# supports 'cling' |
771 | 778 |
for alloc_policy in "contiguous", "cling", "normal": |
772 |
result = utils.RunCmd(["lvextend", "--alloc", alloc_policy, |
|
773 |
"-L", "+%dm" % amount, self.dev_path]) |
|
779 |
result = utils.RunCmd(cmd + ["--alloc", alloc_policy, self.dev_path]) |
|
774 | 780 |
if not result.failed: |
775 | 781 |
return |
776 | 782 |
_ThrowError("Can't grow LV %s: %s", self.dev_path, result.output) |
... | ... | |
1911 | 1917 |
cls._InitMeta(aminor, meta.dev_path) |
1912 | 1918 |
return cls(unique_id, children, size) |
1913 | 1919 |
|
1914 |
def Grow(self, amount): |
|
1920 |
def Grow(self, amount, dryrun):
|
|
1915 | 1921 |
"""Resize the DRBD device and its backing storage. |
1916 | 1922 |
|
1917 | 1923 |
""" |
... | ... | |
1919 | 1925 |
_ThrowError("drbd%d: Grow called while not attached", self._aminor) |
1920 | 1926 |
if len(self._children) != 2 or None in self._children: |
1921 | 1927 |
_ThrowError("drbd%d: cannot grow diskless device", self.minor) |
1922 |
self._children[0].Grow(amount) |
|
1928 |
self._children[0].Grow(amount, dryrun) |
|
1929 |
if dryrun: |
|
1930 |
# DRBD does not support dry-run mode, so we'll return here |
|
1931 |
return |
|
1923 | 1932 |
result = utils.RunCmd(["drbdsetup", self.dev_path, "resize", "-s", |
1924 | 1933 |
"%dm" % (self.size + amount)]) |
1925 | 1934 |
if result.failed: |
... | ... | |
2001 | 2010 |
# TODO: implement rename for file-based storage |
2002 | 2011 |
_ThrowError("Rename is not supported for file-based storage") |
2003 | 2012 |
|
2004 |
def Grow(self, amount): |
|
2013 |
def Grow(self, amount, dryrun):
|
|
2005 | 2014 |
"""Grow the file |
2006 | 2015 |
|
2007 | 2016 |
@param amount: the amount (in mebibytes) to grow with |
... | ... | |
2012 | 2021 |
current_size = self.GetActualSize() |
2013 | 2022 |
new_size = current_size + amount * 1024 * 1024 |
2014 | 2023 |
assert new_size > current_size, "Cannot Grow with a negative amount" |
2024 |
# We can't really simulate the growth |
|
2025 |
if dryrun: |
|
2026 |
return |
|
2015 | 2027 |
try: |
2016 | 2028 |
f = open(self.dev_path, "a+") |
2017 | 2029 |
f.truncate(new_size) |
... | ... | |
2173 | 2185 |
""" |
2174 | 2186 |
pass |
2175 | 2187 |
|
2176 |
def Grow(self, amount): |
|
2188 |
def Grow(self, amount, dryrun):
|
|
2177 | 2189 |
"""Grow the logical volume. |
2178 | 2190 |
|
2179 | 2191 |
""" |
Also available in: Unified diff