
On 2014年01月18日 01:22, Aline Manera wrote:
On 01/15/2014 07:14 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Before creating nfs pool, reload the prevalidation for the path and see if it is able to complish a quick mount. If not, deny this storage pool from being created.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 671af02..f49dc68 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -68,9 +68,11 @@ from kimchi.featuretests import FeatureTests from kimchi.iscsi import TargetClient from kimchi.isoinfo import IsoImage from kimchi.objectstore import ObjectStore +from kimchi.rollbackcontext import RollbackContext from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log +from kimchi.utils import run_command, parse_cmd_output from kimchi.vmtemplate import VMTemplate
@@ -1557,8 +1559,31 @@ class NetfsPoolDef(StoragePoolDef): self.path = '/var/lib/kimchi/nfs_mount/' + self.poolArgs['name']
def prepare(self, conn): - # TODO: Verify the NFS export can be actually mounted. - pass + export_path = "%s:%s" % ( + self.poolArgs['source']['host'], self.poolArgs['source']['path']) + mount_cmd = ["mount", "-o", 'soft,timeo=100,retrans=3,retry=0', + export_path, self.path] + umount_cmd = ["umount", "-f", export_path] + mounted = False +
+ if not os.path.isdir(self.path): + os.mkdir(self.path)
os.mkdir only creates one directory which can be a problem if '/var/lib/kimchi/nfs_mount/' doesn't exist
I'd suggest to use a temp dir to mount it (instead of the real path) And then libvirt will be responsible to create the path when creating the storage pool. ACK
+ + with RollbackContext() as rollback: + run_command(mount_cmd, 30) + rollback.prependDefer(run_command, umount_cmd) + + with open("/proc/mounts" , "rb") as f: + rawMounts = f.read() + output_items = ['dev_path', 'mnt_point', 'type'] + mounts = parse_cmd_output(rawMounts, output_items) + for item in mounts: + if 'dev_path' in item and item['dev_path'] == export_path: + mounted = True + + if not mounted: + raise InvalidParameter( + "Export path %s may block during nfs mount" % export_path)
@property def xml(self):