summaryrefslogtreecommitdiffstats
path: root/swift/1.4.8/plugins/Glusterfs.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2012-11-07 12:37:26 -0500
committerVijay Bellur <vbellur@redhat.com>2012-11-16 04:52:06 -0800
commite8d95655d5e73462723799d20e59bc4f21bdf973 (patch)
treeb1e37a514241340834896e51e6127bff6c577e75 /swift/1.4.8/plugins/Glusterfs.py
parent05cc14c2d301934d79ee37cd36f498247b7a9886 (diff)
object-storage: refactor to use swift devices
Refactor code to use the devices configuration file setting for account, container, and object servers, dropping mount_path from the fs.conf file, and constructing new account, container and object server rings. This removes the next to last set of diffs in the swift diff file. See BZ 870589 (https://bugzilla.redhat.com/show_bug.cgi?id=870589). The key to the change is the dropping of the pre-built account, container and object rings, instead providing a script that will generate them for the user given the gluster volume name in use. In addition, we override the Swift check_mount() method and replace it with Gluster's which attempts to "auto-mount" if it is not already mounted. The following is an enumeration of the changes contained in this refactoring: * The refactoring to override the Swift check_mount() involved condensing a lot of code, removing redundancies and simplifying methods across a number of modules * Drop checking the mount point in the low level DiskDir, DiskAccount and DiskFile objects now that Swift's normal mount checking is used, and enable it by default in the template configuration file * Add missing get_container_timestamp() method for DiskAccount objects * Fix the plugin RPM spec file to provide the new ring builders, and while we were at it, finally fix the over-writing of the configuration files on install * Bug fixes * The monkey patched version of check_object_creation was not working correctly due to a missing import of HTTPBadRequest and a bad reference to validate_obj_name_component() * Only have the utils module import the plugins constraints module for the side effect of monkey patching if gluster is enabled * Removed the db_file.db file in the tree since it is created on the fly * Updated 2011 copyright notices to 2012 Change-Id: I8f4454576b1423021c9bbf3c36176f8db51e62c0 BUG: 870589 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4179 Reviewed-by: Pete Zaitcev <zaitcev@redhat.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Tested-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Mohammed Junaid <junaid@redhat.com>
Diffstat (limited to 'swift/1.4.8/plugins/Glusterfs.py')
-rw-r--r--swift/1.4.8/plugins/Glusterfs.py83
1 files changed, 39 insertions, 44 deletions
diff --git a/swift/1.4.8/plugins/Glusterfs.py b/swift/1.4.8/plugins/Glusterfs.py
index 35b0c2f5938..c176a247b9b 100644
--- a/swift/1.4.8/plugins/Glusterfs.py
+++ b/swift/1.4.8/plugins/Glusterfs.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 Red Hat, Inc.
+# Copyright (c) 2012 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@ import logging
import os, fcntl, time
from ConfigParser import ConfigParser
from swift.common.utils import TRUE_VALUES
-from hashlib import md5
from swift.plugins.fs_utils import mkdirs
@@ -24,17 +23,12 @@ from swift.plugins.fs_utils import mkdirs
# Read the fs.conf file once at startup (module load)
#
_fs_conf = ConfigParser()
-MOUNT_PATH = '/mnt/gluster-object'
AUTH_ACCOUNT = 'auth'
MOUNT_IP = 'localhost'
REMOTE_CLUSTER = False
OBJECT_ONLY = False
if _fs_conf.read(os.path.join('/etc/swift', 'fs.conf')):
try:
- MOUNT_PATH = _fs_conf.get('DEFAULT', 'mount_path', '/mnt/gluster-object')
- except (NoSectionError, NoOptionError):
- pass
- try:
AUTH_ACCOUNT = _fs_conf.get('DEFAULT', 'auth_account', 'auth')
except (NoSectionError, NoOptionError):
pass
@@ -53,12 +47,6 @@ if _fs_conf.read(os.path.join('/etc/swift', 'fs.conf')):
NAME = 'glusterfs'
-def strip_obj_storage_path(path, mp=MOUNT_PATH):
- """
- strip the mount path off, also stripping the leading and trailing slashes
- """
- return path.replace(mp, '').strip(os.path.sep)
-
def _busy_wait(full_mount_path):
# Iterate for definite number of time over a given
# interval for successful mount
@@ -66,13 +54,26 @@ def _busy_wait(full_mount_path):
if os.path.ismount(os.path.join(full_mount_path)):
return True
time.sleep(2)
+ logging.error('Busy wait for mount timed out for mount %s', full_mount_path)
return False
-def mount(account):
- full_mount_path = os.path.join(MOUNT_PATH, account)
- export = get_export_from_account_id(account)
+def mount(root, drive):
+ # FIXME: Possible thundering herd problem here
- pid_dir = "/var/lib/glusterd/vols/%s/run/" % export
+ el = _get_export_list()
+ for export in el:
+ if drive == export:
+ break
+ else:
+ logging.error('No export found in %r matching drive %s', el, drive)
+ return False
+
+ # NOTE: root is typically the default value of /mnt/gluster-object
+ full_mount_path = os.path.join(root, drive)
+ if not os.path.isdir(full_mount_path):
+ mkdirs(full_mount_path)
+
+ pid_dir = "/var/lib/glusterd/vols/%s/run/" % drive
pid_file = os.path.join(pid_dir, 'swift.pid');
if not os.path.exists(pid_dir):
@@ -85,52 +86,46 @@ def mount(account):
except:
ex = sys.exc_info()[1]
if isinstance(ex, IOError) and ex.errno in (EACCES, EAGAIN):
- # This means that some other process is mounting the
- # filesystem, so wait for the mount process to complete
+ # This means that some other process is mounting the
+ # filesystem, so wait for the mount process to complete
return _busy_wait(full_mount_path)
mnt_cmd = 'mount -t glusterfs %s:%s %s' % (MOUNT_IP, export, \
full_mount_path)
if os.system(mnt_cmd) or not _busy_wait(full_mount_path):
- raise Exception('Mount failed %s: %s' % (NAME, mnt_cmd))
+ logging.error('Mount failed %s: %s', NAME, mnt_cmd)
+ return False
return True
def unmount(full_mount_path):
+ # FIXME: Possible thundering herd problem here
+
umnt_cmd = 'umount %s 2>> /dev/null' % full_mount_path
if os.system(umnt_cmd):
logging.error('Unable to unmount %s %s' % (full_mount_path, NAME))
-def get_export_list():
+def _get_export_list():
if REMOTE_CLUSTER:
cmnd = 'ssh %s gluster volume info' % MOUNT_IP
else:
cmnd = 'gluster volume info'
+ export_list = []
+
if os.system(cmnd + ' >> /dev/null'):
if REMOTE_CLUSTER:
- raise Exception('Getting volume info failed %s, make sure to have \
- passwordless ssh on %s', NAME, MOUNT_IP)
+ logging.error('Getting volume info failed %s, make sure to have '\
+ 'passwordless ssh on %s', NAME, MOUNT_IP)
else:
- raise Exception('Getting volume failed %s', NAME)
-
- export_list = []
- fp = os.popen(cmnd)
- while True:
- item = fp.readline()
- if not item:
- break
- item = item.strip('\n').strip(' ')
- if item.lower().startswith('volume name:'):
- export_list.append(item.split(':')[1].strip(' '))
+ logging.error('Getting volume failed %s', NAME)
+ else:
+ fp = os.popen(cmnd)
+ while True:
+ item = fp.readline()
+ if not item:
+ break
+ item = item.strip('\n').strip(' ')
+ if item.lower().startswith('volume name:'):
+ export_list.append(item.split(':')[1].strip(' '))
return export_list
-
-def get_export_from_account_id(account):
- if not account:
- raise ValueError('No account given')
-
- for export in get_export_list():
- if account == 'AUTH_' + export:
- return export
-
- raise Exception('No export found %s %s' % (account, NAME))