This is always called with False from backend for now.
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
_Fail("Cannot find block device %s", disk)
try:
_Fail("Cannot find block device %s", disk)
try:
+ r_dev.Grow(amount, False)
except errors.BlockDeviceError, err:
_Fail("Failed to grow block device: %s", err, exc=True)
except errors.BlockDeviceError, err:
_Fail("Failed to grow block device: %s", err, exc=True)
for child in self._children:
child.SetInfo(text)
for child in self._children:
child.SetInfo(text)
- def Grow(self, amount):
+ def Grow(self, amount, dryrun):
"""Grow the block device.
"""Grow the block device.
@param amount: the amount (in mebibytes) to grow with
@param amount: the amount (in mebibytes) to grow with
+ @type dryrun: boolean
+ @param dryrun: whether to execute the operation in simulation mode
+ only, without actually increasing the size
"""
raise NotImplementedError
"""
raise NotImplementedError
_ThrowError("Command: %s error: %s - %s", result.cmd, result.fail_reason,
result.output)
_ThrowError("Command: %s error: %s - %s", result.cmd, result.fail_reason,
result.output)
- def Grow(self, amount):
+ def Grow(self, amount, dryrun):
"""Grow the logical volume.
"""
"""Grow the logical volume.
"""
rest = amount % full_stripe_size
if rest != 0:
amount += full_stripe_size - rest
rest = amount % full_stripe_size
if rest != 0:
amount += full_stripe_size - rest
+ cmd = ["lvextend", "-L", "+%dm" % amount]
+ if dryrun:
+ cmd.append("--test")
# we try multiple algorithms since the 'best' ones might not have
# space available in the right place, but later ones might (since
# they have less constraints); also note that only recent LVM
# supports 'cling'
for alloc_policy in "contiguous", "cling", "normal":
# we try multiple algorithms since the 'best' ones might not have
# space available in the right place, but later ones might (since
# they have less constraints); also note that only recent LVM
# supports 'cling'
for alloc_policy in "contiguous", "cling", "normal":
- result = utils.RunCmd(["lvextend", "--alloc", alloc_policy,
- "-L", "+%dm" % amount, self.dev_path])
+ result = utils.RunCmd(cmd + ["--alloc", alloc_policy, self.dev_path])
if not result.failed:
return
_ThrowError("Can't grow LV %s: %s", self.dev_path, result.output)
if not result.failed:
return
_ThrowError("Can't grow LV %s: %s", self.dev_path, result.output)
cls._InitMeta(aminor, meta.dev_path)
return cls(unique_id, children, size)
cls._InitMeta(aminor, meta.dev_path)
return cls(unique_id, children, size)
- def Grow(self, amount):
+ def Grow(self, amount, dryrun):
"""Resize the DRBD device and its backing storage.
"""
"""Resize the DRBD device and its backing storage.
"""
_ThrowError("drbd%d: Grow called while not attached", self._aminor)
if len(self._children) != 2 or None in self._children:
_ThrowError("drbd%d: cannot grow diskless device", self.minor)
_ThrowError("drbd%d: Grow called while not attached", self._aminor)
if len(self._children) != 2 or None in self._children:
_ThrowError("drbd%d: cannot grow diskless device", self.minor)
- self._children[0].Grow(amount)
+ self._children[0].Grow(amount, dryrun)
+ if dryrun:
+ # DRBD does not support dry-run mode, so we'll return here
+ return
result = utils.RunCmd(["drbdsetup", self.dev_path, "resize", "-s",
"%dm" % (self.size + amount)])
if result.failed:
result = utils.RunCmd(["drbdsetup", self.dev_path, "resize", "-s",
"%dm" % (self.size + amount)])
if result.failed:
# TODO: implement rename for file-based storage
_ThrowError("Rename is not supported for file-based storage")
# TODO: implement rename for file-based storage
_ThrowError("Rename is not supported for file-based storage")
- def Grow(self, amount):
+ def Grow(self, amount, dryrun):
"""Grow the file
@param amount: the amount (in mebibytes) to grow with
"""Grow the file
@param amount: the amount (in mebibytes) to grow with
current_size = self.GetActualSize()
new_size = current_size + amount * 1024 * 1024
assert new_size > current_size, "Cannot Grow with a negative amount"
current_size = self.GetActualSize()
new_size = current_size + amount * 1024 * 1024
assert new_size > current_size, "Cannot Grow with a negative amount"
+ # We can't really simulate the growth
+ if dryrun:
+ return
try:
f = open(self.dev_path, "a+")
f.truncate(new_size)
try:
f = open(self.dev_path, "a+")
f.truncate(new_size)
- def Grow(self, amount):
+ def Grow(self, amount, dryrun):
"""Grow the logical volume.
"""
"""Grow the logical volume.
"""