[project-kimchi][PATCHv2 0/2] NFS prevalidation

7 views
Skip to first unread message

lvr...@linux.vnet.ibm.com

unread,
Dec 18, 2013, 4:34:43 AM12/18/13
to project...@googlegroups.com, Royce Lv
From: Royce Lv <lvr...@linux.vnet.ibm.com>

v1>v2, move nfs checking to util to avoid misunderstanding.
This patchset solves following problem:
1. libvirt uses local directory when nfs target path is not accessible,
this patch denies this unaccessible path instead.
2. libvirt storage subsystem hang for a long period, with a quick checking,
storage pool operation will not hang if pre-checked.
3. Future access control check will do in prevalidation,
this prevents qemu manipulate storage pool of no read access to make early warning.

Royce Lv (2):
utils: Add nfs prevalication
Integrate nfs path check before create nfs pool

src/kimchi/model.py | 7 ++++++-
src/kimchi/utils.py | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)

--
1.8.1.2

lvr...@linux.vnet.ibm.com

unread,
Dec 18, 2013, 4:34:44 AM12/18/13
to project...@googlegroups.com, Royce Lv
From: Royce Lv <lvr...@linux.vnet.ibm.com>

Abstract a helper function to parse cmd result.
Usage:
(1)get cmd result with subprocess.call or subprocess.Popen
(2) call pass_cmd_output to get formated outputs
Example:
blkid = subprocess.Popen(["cat", "/proc/mounts"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs = blkid.communicate()[0]
output_items= ['path', 'mnt_point', 'type', 'option']
utils.parse_cmd_output(outs, output_items)
Sample output:
[{'path': '/dev/sda8', 'type': 'ext4',
'option': 'rw,relatime,data=ordered', 'mnt_point': '/home'},
{'path': 'localhost:/home/royce/isorepo', 'type': 'nfs4',
'option': 'rw...addr=127.0.0.1', 'mnt_point': '/mnt'}]

To prevent future mount of nfs path will hang,
we will try nfs path with a quick mount,
if this check fails, report warning to user.

Signed-off-by: Royce Lv <lvr...@linux.vnet.ibm.com>
---
src/kimchi/utils.py | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)

diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index f7eda93..14b9c8a 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -22,6 +22,9 @@
#

import cherrypy
+import subprocess
+import tempfile
+import threading
import os


@@ -84,3 +87,38 @@ def import_class(class_path):

def import_module(module_name):
return __import__(module_name, fromlist=[''])
+
+def parse_cmd_output(output, output_items):
+ res = []
+ for line in output.split("\n"):
+ res.append(dict(zip(output_items, line.split())))
+
+ return res
+
+def check_nfs_export(export_path):
+ res = False
+ outputs = None
+ mnt_point = tempfile.mkdtemp(dir='/tmp')
+ cmd = ["mount", "-o", 'soft,timeo=100,retrans=3,retry=0',
+ export_path, mnt_point]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ thread = threading.Thread(target = proc.communicate)
+ thread.start()
+ thread.join(30)
+
+ if thread.is_alive():
+ proc.kill()
+ thread.join()
+
+ with open("/proc/mounts" , "rb") as f:
+ outputs = f.read()
+ output_items = ['dev_path', 'mnt_point', 'type']
+ mounts = parse_cmd_output(outputs, output_items)
+ for item in mounts:
+ if 'dev_path' in item and item['dev_path'] == export_path:
+ res = True
+ cmd = ["umount", "-f", export_path]
+ subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ return res
--
1.8.1.2

lvr...@linux.vnet.ibm.com

unread,
Dec 18, 2013, 4:34:45 AM12/18/13
to project...@googlegroups.com, Royce Lv
From: Royce Lv <lvr...@linux.vnet.ibm.com>

Before creating nfs pool, add a 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 <lvr...@linux.vnet.ibm.com>
---
src/kimchi/model.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index 73c18ac..705e768 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -69,7 +69,7 @@ from kimchi.networkxml import to_network_xml
from kimchi.objectstore import ObjectStore
from kimchi.scan import Scanner
from kimchi.screenshot import VMScreenshot
-from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins
+from kimchi.utils import kimchi_log, is_digit, get_enabled_plugins, check_nfs_export
from kimchi.vmtemplate import VMTemplate


@@ -991,6 +991,11 @@ class Model(object):

if params['type'] == 'kimchi-iso':
task_id = self._do_deep_scan(params)
+ if params['type'] == 'netfs':
+ export_path = params['nfsserver'] + ':' + params['nfspath']
+ if not check_nfs_export(export_path):
+ raise InvalidParameter(
+ "Export path %s may block during nfs mount" % export_path)
xml = _get_pool_xml(**params)
except KeyError, key:
raise MissingParameter(key)
--
1.8.1.2

Aline Manera

unread,
Dec 18, 2013, 7:34:57 AM12/18/13
to lvr...@linux.vnet.ibm.com, project...@googlegroups.com

Reviewed-by: Aline Manera <ali...@linux.vnet.ibm.com>

Aline Manera

unread,
Dec 18, 2013, 7:35:35 AM12/18/13
to lvr...@linux.vnet.ibm.com, project...@googlegroups.com

Reviewed-by: Aline Manera <ali...@linux.vnet.ibm.com>

On 12/18/2013 07:34 AM, lvr...@linux.vnet.ibm.com wrote:
Reply all
Reply to author
Forward
0 new messages