summaryrefslogtreecommitdiffstats
path: root/swift
diff options
context:
space:
mode:
Diffstat (limited to 'swift')
-rw-r--r--swift/1.4.8/gluster-swift-plugin.spec15
-rw-r--r--swift/1.4.8/gluster-swift.spec2
-rw-r--r--swift/1.4.8/plugins/DiskDir.py17
-rw-r--r--swift/1.4.8/plugins/DiskFile.py18
-rw-r--r--swift/1.4.8/plugins/Glusterfs.py83
-rwxr-xr-xswift/1.4.8/plugins/bin/gluster-swift-gen-builders19
-rw-r--r--swift/1.4.8/plugins/conf/account-server/1.conf-gluster6
-rw-r--r--swift/1.4.8/plugins/conf/account.builderbin786843 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/account.ring.gzbin739 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/container-server/1.conf-gluster6
-rw-r--r--swift/1.4.8/plugins/conf/container.builderbin786843 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/container.ring.gzbin741 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/db_file.db0
-rw-r--r--swift/1.4.8/plugins/conf/fs.conf-gluster3
-rw-r--r--swift/1.4.8/plugins/conf/object-server/1.conf-gluster6
-rw-r--r--swift/1.4.8/plugins/conf/object.builderbin786843 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/object.ring.gzbin738 -> 0 bytes
-rw-r--r--swift/1.4.8/plugins/conf/proxy-server.conf-gluster14
-rw-r--r--swift/1.4.8/plugins/constraints.py25
-rw-r--r--swift/1.4.8/plugins/fs_utils.py2
-rw-r--r--swift/1.4.8/plugins/utils.py70
-rw-r--r--swift/1.4.8/swift.diff133
-rw-r--r--swift/1.4.8/test/unit/plugins/test_utils.py22
23 files changed, 198 insertions, 243 deletions
diff --git a/swift/1.4.8/gluster-swift-plugin.spec b/swift/1.4.8/gluster-swift-plugin.spec
index 4e4ea4f..0a1637d 100644
--- a/swift/1.4.8/gluster-swift-plugin.spec
+++ b/swift/1.4.8/gluster-swift-plugin.spec
@@ -13,7 +13,7 @@
%define _confdir /etc/swift
%define _swiftdir /usr/lib/python2.6/site-packages/swift
%define _ufo_version 1.0
-%define _ufo_release 8
+%define _ufo_release 12
Summary : GlusterFS Unified File and Object Storage.
Name : gluster-swift-plugin
@@ -44,6 +44,7 @@ rm -rf %{buildroot}
mkdir -p %{buildroot}/%{_swiftdir}/plugins/middleware
mkdir -p %{buildroot}/%{_confdir}/
+mkdir -p %{buildroot}/%{_bindir}/
cp constraints.py %{buildroot}/%{_swiftdir}/plugins
cp DiskDir.py %{buildroot}/%{_swiftdir}/plugins
@@ -58,8 +59,16 @@ cp middleware/gluster.py %{buildroot}/%{_swiftdir}/plugins/middleware
cp -r conf/* %{buildroot}/%{_confdir}/
+cp bin/gluster-swift-gen-builders %{buildroot}/%{_bindir}/
+
%files
%defattr(-,root,root)
-%{_swiftdir}/plugins/middleware
+%docdir conf
%{_swiftdir}/plugins
-%{_confdir}/
+%{_bindir}/gluster-swift-gen-builders
+%config %{_confdir}/account-server/1.conf-gluster
+%config %{_confdir}/container-server/1.conf-gluster
+%config %{_confdir}/object-server/1.conf-gluster
+%config %{_confdir}/swift.conf-gluster
+%config %{_confdir}/proxy-server.conf-gluster
+%config %{_confdir}/fs.conf-gluster
diff --git a/swift/1.4.8/gluster-swift.spec b/swift/1.4.8/gluster-swift.spec
index f9d9289..a525e9e 100644
--- a/swift/1.4.8/gluster-swift.spec
+++ b/swift/1.4.8/gluster-swift.spec
@@ -4,7 +4,7 @@
Name: gluster-swift
Version: 1.4.8
-Release: 8%{?dist}
+Release: 12%{?dist}
Summary: OpenStack Object Storage (swift)
Group: Development/Languages
diff --git a/swift/1.4.8/plugins/DiskDir.py b/swift/1.4.8/plugins/DiskDir.py
index 6887bec..b12827c 100644
--- a/swift/1.4.8/plugins/DiskDir.py
+++ b/swift/1.4.8/plugins/DiskDir.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,16 +16,15 @@
import os, errno
from swift.plugins.utils import clean_metadata, dir_empty, rmdirs, mkdirs, \
- validate_account, validate_container, check_valid_account, is_marker, \
- get_container_details, get_account_details, get_container_metadata, \
- create_container_metadata, \
+ validate_account, validate_container, is_marker, get_container_details, \
+ get_account_details, get_container_metadata, create_container_metadata, \
create_account_metadata, DEFAULT_GID, DEFAULT_UID, validate_object, \
create_object_metadata, read_metadata, write_metadata, X_CONTENT_TYPE, \
X_CONTENT_LENGTH, X_TIMESTAMP, X_PUT_TIMESTAMP, X_TYPE, X_ETAG, \
X_OBJECTS_COUNT, X_BYTES_USED, X_CONTAINER_COUNT, CONTAINER
from swift.plugins import Glusterfs
-from swift.common.constraints import CONTAINER_LISTING_LIMIT, check_mount
+from swift.common.constraints import CONTAINER_LISTING_LIMIT
from swift.common.utils import normalize_timestamp, TRUE_VALUES
@@ -163,8 +162,6 @@ class DiskDir(DiskCommon):
# Note that the account name has a one-to-one mapping to the gluster
# mount point, or volume name.
self.account = account
- if not check_mount(path, account):
- check_valid_account(account)
assert logger is not None
self.logger = logger
self.metadata = {}
@@ -494,3 +491,9 @@ class DiskAccount(DiskDir):
if include_metadata:
data['metadata'] = self.metadata
return data
+
+ def get_container_timestamp(self, container):
+ cont_path = os.path.join(self.datadir, container)
+ metadata = read_metadata(cont_path)
+
+ return int(metadata.get(X_PUT_TIMESTAMP, ('0',0))[0]) or None
diff --git a/swift/1.4.8/plugins/DiskFile.py b/swift/1.4.8/plugins/DiskFile.py
index 61b1c9c..a57b2ec 100644
--- a/swift/1.4.8/plugins/DiskFile.py
+++ b/swift/1.4.8/plugins/DiskFile.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.
@@ -19,14 +19,12 @@ from tempfile import mkstemp
from contextlib import contextmanager
from swift.common.utils import normalize_timestamp, renamer
from swift.plugins.utils import mkdirs, rmdirs, validate_object, \
- check_valid_account, create_object_metadata, do_open, \
- do_close, do_unlink, do_chown, do_stat, do_listdir, read_metadata,\
- write_metadata
-from swift.common.constraints import check_mount
-from swift.plugins.utils import X_CONTENT_TYPE, X_CONTENT_LENGTH, X_TIMESTAMP,\
+ create_object_metadata, do_open, do_close, do_unlink, do_chown, \
+ do_stat, do_listdir, read_metadata, write_metadata
+from swift.plugins.utils import X_CONTENT_TYPE, X_CONTENT_LENGTH, X_TIMESTAMP, \
X_PUT_TIMESTAMP, X_TYPE, X_ETAG, X_OBJECTS_COUNT, X_BYTES_USED, \
- X_OBJECT_TYPE, FILE, DIR, MARKER_DIR, OBJECT, \
- DIR_TYPE, FILE_TYPE, DEFAULT_UID, DEFAULT_GID
+ X_OBJECT_TYPE, FILE, DIR, MARKER_DIR, OBJECT, DIR_TYPE, FILE_TYPE, \
+ DEFAULT_UID, DEFAULT_GID
import logging
from swift.obj.server import DiskFile
@@ -74,11 +72,7 @@ class Gluster_DiskFile(DiskFile):
self.name = container
#Absolute path for obj directory.
self.datadir = os.path.join(path, device, self.name)
-
self.device_path = os.path.join(path, device)
- if not check_mount(path, device):
- check_valid_account(account)
-
self.container_path = os.path.join(path, device, container)
self.tmpdir = os.path.join(path, device, 'tmp')
self.logger = logger
diff --git a/swift/1.4.8/plugins/Glusterfs.py b/swift/1.4.8/plugins/Glusterfs.py
index 35b0c2f..c176a24 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))
diff --git a/swift/1.4.8/plugins/bin/gluster-swift-gen-builders b/swift/1.4.8/plugins/bin/gluster-swift-gen-builders
new file mode 100755
index 0000000..b89cd15
--- /dev/null
+++ b/swift/1.4.8/plugins/bin/gluster-swift-gen-builders
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+function create {
+ swift-ring-builder $1 create 0 1 1
+ swift-ring-builder $1 add z1-127.0.0.1:$2/$3_ 100.0
+ swift-ring-builder $1 rebalance
+ swift-ring-builder $1
+}
+
+if [ "$1x" = "x" ]; then
+ echo "Please specify the gluster volume name to use."
+ exit 1
+fi
+
+# Note that these port numbers must match the configured values for the
+# various servers in their configuration files.
+create account.builder 6012 $1
+create container.builder 6011 $1
+create object.builder 6010 $1
diff --git a/swift/1.4.8/plugins/conf/account-server/1.conf-gluster b/swift/1.4.8/plugins/conf/account-server/1.conf-gluster
index 911e283..c7a4c10 100644
--- a/swift/1.4.8/plugins/conf/account-server/1.conf-gluster
+++ b/swift/1.4.8/plugins/conf/account-server/1.conf-gluster
@@ -1,7 +1,7 @@
[DEFAULT]
-devices = /srv/1/node
-mount_check = false
-bind_port = 6012
+devices = /mnt/gluster-object
+mount_check = true
+bind_port = 6012 # Be sure to keep in sync with /usr/bin/gluster-swift-gen-builders
user = root
log_facility = LOG_LOCAL2
diff --git a/swift/1.4.8/plugins/conf/account.builder b/swift/1.4.8/plugins/conf/account.builder
deleted file mode 100644
index 2943b9c..0000000
--- a/swift/1.4.8/plugins/conf/account.builder
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/account.ring.gz b/swift/1.4.8/plugins/conf/account.ring.gz
deleted file mode 100644
index e1a5e6a..0000000
--- a/swift/1.4.8/plugins/conf/account.ring.gz
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/container-server/1.conf-gluster b/swift/1.4.8/plugins/conf/container-server/1.conf-gluster
index eb5650a..2b97eef 100644
--- a/swift/1.4.8/plugins/conf/container-server/1.conf-gluster
+++ b/swift/1.4.8/plugins/conf/container-server/1.conf-gluster
@@ -1,7 +1,7 @@
[DEFAULT]
-devices = /srv/1/node
-mount_check = false
-bind_port = 6011
+devices = /mnt/gluster-object
+mount_check = true
+bind_port = 6011 # Be sure to keep in sync with /usr/bin/gluster-swift-gen-builders
user = root
log_facility = LOG_LOCAL2
diff --git a/swift/1.4.8/plugins/conf/container.builder b/swift/1.4.8/plugins/conf/container.builder
deleted file mode 100644
index 6031d79..0000000
--- a/swift/1.4.8/plugins/conf/container.builder
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/container.ring.gz b/swift/1.4.8/plugins/conf/container.ring.gz
deleted file mode 100644
index fdbcb18..0000000
--- a/swift/1.4.8/plugins/conf/container.ring.gz
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/db_file.db b/swift/1.4.8/plugins/conf/db_file.db
deleted file mode 100644
index e69de29..0000000
--- a/swift/1.4.8/plugins/conf/db_file.db
+++ /dev/null
diff --git a/swift/1.4.8/plugins/conf/fs.conf-gluster b/swift/1.4.8/plugins/conf/fs.conf-gluster
index b6ec512..0bd21ba 100644
--- a/swift/1.4.8/plugins/conf/fs.conf-gluster
+++ b/swift/1.4.8/plugins/conf/fs.conf-gluster
@@ -1,9 +1,8 @@
[DEFAULT]
-mount_path = /mnt/gluster-object
auth_account = auth
#ip of the fs server.
mount_ip = localhost
#fs server need not be local, remote server can also be used,
#set remote_cluster=yes for using remote server.
remote_cluster = no
-object_only = no \ No newline at end of file
+object_only = no
diff --git a/swift/1.4.8/plugins/conf/object-server/1.conf-gluster b/swift/1.4.8/plugins/conf/object-server/1.conf-gluster
index 13dda69..62e2fb4 100644
--- a/swift/1.4.8/plugins/conf/object-server/1.conf-gluster
+++ b/swift/1.4.8/plugins/conf/object-server/1.conf-gluster
@@ -1,7 +1,7 @@
[DEFAULT]
-devices = /srv/1/node
-mount_check = false
-bind_port = 6010
+devices = /mnt/gluster-object
+mount_check = true
+bind_port = 6010 # Be sure to keep in sync with /usr/bin/gluster-swift-gen-builders
user = root
log_facility = LOG_LOCAL2
diff --git a/swift/1.4.8/plugins/conf/object.builder b/swift/1.4.8/plugins/conf/object.builder
deleted file mode 100644
index ce45350..0000000
--- a/swift/1.4.8/plugins/conf/object.builder
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/object.ring.gz b/swift/1.4.8/plugins/conf/object.ring.gz
deleted file mode 100644
index 73e88d5..0000000
--- a/swift/1.4.8/plugins/conf/object.ring.gz
+++ /dev/null
Binary files differ
diff --git a/swift/1.4.8/plugins/conf/proxy-server.conf-gluster b/swift/1.4.8/plugins/conf/proxy-server.conf-gluster
index 9bec642..b5e1f6f 100644
--- a/swift/1.4.8/plugins/conf/proxy-server.conf-gluster
+++ b/swift/1.4.8/plugins/conf/proxy-server.conf-gluster
@@ -13,6 +13,18 @@ account_autocreate = true
[filter:tempauth]
use = egg:swift#tempauth
+# Here you need to add users explicitly. See the OpenStack Swift Deployment
+# Guide for more information. The user and user64 directives take the
+# following form:
+# user_<account>_<username> = <key> [group] [group] [...] [storage_url]
+# user64_<account_b64>_<username_b64> = <key> [group] [group] [...] [storage_url]
+# Where you use user64 for accounts and/or usernames that include underscores.
+#
+# NOTE (and WARNING): The account name must match the device name specified
+# when generating the account, container, and object build rings.
+#
+# E.g.
+# user_ufo0_admin = abc123 .admin
[filter:healthcheck]
use = egg:swift#healthcheck
@@ -21,4 +33,4 @@ use = egg:swift#healthcheck
use = egg:swift#memcache
[filter:gluster]
-use = egg:swift#gluster \ No newline at end of file
+use = egg:swift#gluster
diff --git a/swift/1.4.8/plugins/constraints.py b/swift/1.4.8/plugins/constraints.py
index d522090..6d003b9 100644
--- a/swift/1.4.8/plugins/constraints.py
+++ b/swift/1.4.8/plugins/constraints.py
@@ -13,7 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from webob.exc import HTTPBadRequest
+
import swift.common.constraints
+from swift.plugins import Glusterfs
+
MAX_OBJECT_NAME_COMPONENT_LENGTH = swift.common.constraints.constraints_conf_int(
'max_object_name_component_length', 255)
@@ -25,7 +29,7 @@ def validate_obj_name_component(obj):
return 'cannot be . or ..'
return ''
-# Save the original
+# Save the original check object creation
__check_object_creation = swift.common.constraints.check_object_creation
# Define our new one which invokes the original
@@ -48,7 +52,7 @@ def gluster_check_object_creation(req, object_name):
if ret is None:
for obj in object_name.split('/'):
- reason = validate_obj_name(obj)
+ reason = validate_obj_name_component(obj)
if reason:
bdy = 'Invalid object name "%s", component "%s" %s' \
% (object_name, obj, reason)
@@ -58,4 +62,21 @@ def gluster_check_object_creation(req, object_name):
return ret
+# Replace the original check object creation with ours
swift.common.constraints.check_object_creation = gluster_check_object_creation
+
+# Save the original check mount
+__check_mount = swift.common.constraints.check_mount
+
+# Define our new one which invokes the original
+def gluster_check_mount(root, drive):
+ # FIXME: Potential performance optimization here to not call the original
+ # check mount which makes two stat calls. We could do what they do with
+ # just one.
+ if __check_mount(root, drive):
+ return True
+
+ return Glusterfs.mount(root, drive)
+
+# Replace the original check mount with ours
+swift.common.constraints.check_mount = gluster_check_mount
diff --git a/swift/1.4.8/plugins/fs_utils.py b/swift/1.4.8/plugins/fs_utils.py
index 0c74836..7f5292c 100644
--- a/swift/1.4.8/plugins/fs_utils.py
+++ b/swift/1.4.8/plugins/fs_utils.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.
diff --git a/swift/1.4.8/plugins/utils.py b/swift/1.4.8/plugins/utils.py
index 838c1bd..45990d1 100644
--- a/swift/1.4.8/plugins/utils.py
+++ b/swift/1.4.8/plugins/utils.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.
@@ -137,11 +137,6 @@ def clean_metadata(path):
raise
key += 1
-def get_device_from_account(account):
- if account.startswith(RESELLER_PREFIX):
- device = account.replace(RESELLER_PREFIX, '', 1)
- return device
-
def check_user_xattr(path):
if not os.path.exists(path):
return False
@@ -157,27 +152,6 @@ def check_user_xattr(path):
#Remove xattr may fail in case of concurrent remove.
return True
-def _check_valid_account(account):
- full_mount_path = os.path.join(Glusterfs.MOUNT_PATH, account)
-
- if os.path.ismount(full_mount_path):
- return True
-
- if not _check_account_exists(Glusterfs.get_export_from_account_id(account)):
- logging.error('Account not present %s', account)
- return False
-
- if not os.path.isdir(full_mount_path):
- mkdirs(full_mount_path)
-
- if not Glusterfs.mount(account):
- return False
-
- return True
-
-def check_valid_account(account):
- return _check_valid_account(account)
-
def validate_container(metadata):
if not metadata:
logging.warn('validate_container: No metadata')
@@ -253,9 +227,10 @@ def is_marker(metadata):
else:
return False
-def _update_list(path, const_path, src_list, reg_file=True, object_count=0,
+def _update_list(path, cont_path, src_list, reg_file=True, object_count=0,
bytes_used=0, obj_list=[]):
- obj_path = Glusterfs.strip_obj_storage_path(path, const_path)
+ # strip the prefix off, also stripping the leading and trailing slashes
+ obj_path = path.replace(cont_path, '').strip(os.path.sep)
for i in src_list:
if obj_path:
@@ -270,14 +245,14 @@ def _update_list(path, const_path, src_list, reg_file=True, object_count=0,
return object_count, bytes_used
-def update_list(path, const_path, dirs=[], files=[], object_count=0,
+def update_list(path, cont_path, dirs=[], files=[], object_count=0,
bytes_used=0, obj_list=[]):
- object_count, bytes_used = _update_list (path, const_path, files, True,
- object_count, bytes_used,
- obj_list)
- object_count, bytes_used = _update_list (path, const_path, dirs, False,
- object_count, bytes_used,
- obj_list)
+ object_count, bytes_used = _update_list(path, cont_path, files, True,
+ object_count, bytes_used,
+ obj_list)
+ object_count, bytes_used = _update_list(path, cont_path, dirs, False,
+ object_count, bytes_used,
+ obj_list)
return object_count, bytes_used
@@ -314,7 +289,7 @@ def get_container_details(cont_path, memcache=None):
"""
mkey = ''
if memcache:
- mkey = MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(cont_path)
+ mkey = MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + cont_path
cd = memcache.get(mkey)
if cd:
if not cd.dir_list:
@@ -330,7 +305,7 @@ def get_container_details(cont_path, memcache=None):
if memcache:
memcache.set(mkey, cd)
return cd.obj_list, cd.object_count, cd.bytes_used
-
+
class AccountDetails(object):
""" A simple class to store the three pieces of information associated
@@ -371,7 +346,7 @@ def get_account_details(acc_path, memcache=None):
acc_stats = None
mkey = ''
if memcache:
- mkey = MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(acc_path)
+ mkey = MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + acc_path
ad = memcache.get(mkey)
if ad:
# FIXME: Do we really need to stat the file? If we are object
@@ -481,19 +456,6 @@ def create_account_metadata(acc_path, memcache=None):
metadata = get_account_metadata(acc_path, memcache)
return restore_metadata(acc_path, metadata)
-def _check_account_exists(account):
- if account not in get_account_list():
- logging.warn('Account %s does not exist' % account)
- return False
- else:
- return True
-
-def get_account_list():
- return Glusterfs.get_export_list()
-
-def get_account_id(account):
- return RESELLER_PREFIX + md5(account + HASH_PATH_SUFFIX).hexdigest()
-
_DEFAULT_GLUSTER_ENABLED = os.getenv('GLUSTER_UNIT_TEST_ENABLED', 'no')
__swift_conf = ConfigParser()
@@ -507,3 +469,7 @@ _gluster_enabled = _gluster_enabled_val in TRUE_VALUES
def Gluster_enabled():
return _gluster_enabled
+
+if _gluster_enabled:
+ # Monkey patch only when Gluster enabled
+ import swift.plugins.constraints
diff --git a/swift/1.4.8/swift.diff b/swift/1.4.8/swift.diff
index 3f088e2..59bbbe2 100644
--- a/swift/1.4.8/swift.diff
+++ b/swift/1.4.8/swift.diff
@@ -18,7 +18,7 @@ index d195d34..ef625ff 100644
},
)
diff --git a/swift/account/server.py b/swift/account/server.py
-index 800b3c0..c34d967 100644
+index 800b3c0..eaf9e0d 100644
--- a/swift/account/server.py
+++ b/swift/account/server.py
@@ -1,4 +1,5 @@
@@ -27,34 +27,18 @@ index 800b3c0..c34d967 100644
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
-@@ -35,6 +36,10 @@ from swift.common.utils import get_logger, get_param, hash_path, \
- from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
- check_mount, check_float, check_utf8
- from swift.common.db_replicator import ReplicatorRpc
+@@ -29,6 +30,10 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, \
+ HTTPPreconditionFailed, HTTPConflict
+ import simplejson
+
+from swift.plugins.utils import Gluster_enabled
+if Gluster_enabled():
+ from swift.plugins.DiskDir import DiskAccount
-+ from swift.plugins import Glusterfs
-
-
- DATADIR = 'accounts'
-@@ -45,15 +50,21 @@ class AccountController(object):
-
- def __init__(self, conf):
- self.logger = get_logger(conf, log_route='account-server')
-- self.root = conf.get('devices', '/srv/node')
-- self.mount_check = conf.get('mount_check', 'true').lower() in \
-- ('true', 't', '1', 'on', 'yes', 'y')
-+ if Gluster_enabled():
-+ self.root = Glusterfs.MOUNT_PATH
-+ self.mount_check = False
-+ else:
-+ self.root = conf.get('devices', '/srv/node')
-+ self.mount_check = conf.get('mount_check', 'true').lower() in \
-+ ('true', 't', '1', 'on', 'yes', 'y')
- self.replicator_rpc = ReplicatorRpc(self.root, DATADIR, AccountBroker,
- self.mount_check, logger=self.logger)
- self.auto_create_account_prefix = \
++
+ from swift.common.db import AccountBroker
+ from swift.common.utils import get_logger, get_param, hash_path, \
+ normalize_timestamp, split_path, storage_directory
+@@ -54,6 +59,8 @@ class AccountController(object):
conf.get('auto_create_account_prefix') or '.'
def _get_account_broker(self, drive, part, account):
@@ -64,7 +48,7 @@ index 800b3c0..c34d967 100644
db_dir = storage_directory(DATADIR, part, hsh)
db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
diff --git a/swift/container/server.py b/swift/container/server.py
-index 8a18cfd..f5346ce 100644
+index 8a18cfd..3da0f95 100644
--- a/swift/container/server.py
+++ b/swift/container/server.py
@@ -1,4 +1,5 @@
@@ -73,36 +57,18 @@ index 8a18cfd..f5346ce 100644
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
-@@ -37,6 +38,11 @@ from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
- from swift.common.bufferedhttp import http_connect
- from swift.common.exceptions import ConnectionTimeout
- from swift.common.db_replicator import ReplicatorRpc
+@@ -29,6 +30,10 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
+ HTTPCreated, HTTPInternalServerError, HTTPNoContent, \
+ HTTPNotFound, HTTPPreconditionFailed, HTTPMethodNotAllowed
+
+from swift.plugins.utils import Gluster_enabled
+if Gluster_enabled():
+ from swift.plugins.DiskDir import DiskDir
-+ from swift.plugins import Glusterfs
+
-
- DATADIR = 'containers'
-
-@@ -50,9 +56,13 @@ class ContainerController(object):
-
- def __init__(self, conf):
- self.logger = get_logger(conf, log_route='container-server')
-- self.root = conf.get('devices', '/srv/node/')
-- self.mount_check = conf.get('mount_check', 'true').lower() in \
-- ('true', 't', '1', 'on', 'yes', 'y')
-+ if Gluster_enabled():
-+ self.root = Glusterfs.MOUNT_PATH
-+ self.mount_check = False
-+ else:
-+ self.root = conf.get('devices', '/srv/node/')
-+ self.mount_check = conf.get('mount_check', 'true').lower() in \
-+ ('true', 't', '1', 'on', 'yes', 'y')
- self.node_timeout = int(conf.get('node_timeout', 3))
- self.conn_timeout = float(conf.get('conn_timeout', 0.5))
- self.allowed_sync_hosts = [h.strip()
-@@ -73,6 +83,8 @@ class ContainerController(object):
+ from swift.common.db import ContainerBroker
+ from swift.common.utils import get_logger, get_param, hash_path, \
+ normalize_timestamp, storage_directory, split_path, validate_sync_to
+@@ -73,6 +78,8 @@ class ContainerController(object):
:param container: container name
:returns: ContainerBroker object
"""
@@ -112,7 +78,7 @@ index 8a18cfd..f5346ce 100644
db_dir = storage_directory(DATADIR, part, hsh)
db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
diff --git a/swift/obj/server.py b/swift/obj/server.py
-index 9cca16b..1861f33 100644
+index 9cca16b..448ea5c 100644
--- a/swift/obj/server.py
+++ b/swift/obj/server.py
@@ -1,4 +1,5 @@
@@ -121,19 +87,16 @@ index 9cca16b..1861f33 100644
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
-@@ -45,6 +46,11 @@ from swift.common.exceptions import ConnectionTimeout, DiskFileError, \
- DiskFileNotExist
- from swift.obj.replicator import tpooled_get_hashes, invalidate_hash, \
- quarantine_renamer
-+from swift.plugins.utils import Gluster_enabled
-+if Gluster_enabled():
-+ from swift.plugins.utils import X_TYPE, X_OBJECT_TYPE, FILE, DIR, MARKER_DIR, \
-+ OBJECT, DIR_TYPE, FILE_TYPE
-+ from swift.plugins import Glusterfs
-
+@@ -35,6 +36,8 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \
+ from xattr import getxattr, setxattr
+ from eventlet import sleep, Timeout, tpool
- DATADIR = 'objects'
-@@ -340,6 +346,10 @@ class DiskFile(object):
++from swift.plugins.utils import Gluster_enabled
++
+ from swift.common.utils import mkdirs, normalize_timestamp, \
+ storage_directory, hash_path, renamer, fallocate, \
+ split_path, drop_buffer_cache, get_logger, write_pickle
+@@ -340,6 +343,10 @@ class DiskFile(object):
raise DiskFileNotExist('Data File does not exist.')
@@ -144,24 +107,7 @@ index 9cca16b..1861f33 100644
class ObjectController(object):
"""Implements the WSGI application for the Swift Object Server."""
-@@ -351,9 +361,13 @@ class ObjectController(object):
- /etc/swift/object-server.conf-sample.
- """
- self.logger = get_logger(conf, log_route='object-server')
-- self.devices = conf.get('devices', '/srv/node/')
-- self.mount_check = conf.get('mount_check', 'true').lower() in \
-- ('true', 't', '1', 'on', 'yes', 'y')
-+ if Gluster_enabled():
-+ self.devices = Glusterfs.MOUNT_PATH
-+ self.mount_check = False
-+ else:
-+ self.devices = conf.get('devices', '/srv/node/')
-+ self.mount_check = conf.get('mount_check', 'true').lower() in \
-+ ('true', 't', '1', 'on', 'yes', 'y')
- self.node_timeout = int(conf.get('node_timeout', 3))
- self.conn_timeout = float(conf.get('conn_timeout', 0.5))
- self.disk_chunk_size = int(conf.get('disk_chunk_size', 65536))
-@@ -378,6 +392,15 @@ class ObjectController(object):
+@@ -378,6 +385,15 @@ class ObjectController(object):
self.expiring_objects_container_divisor = \
int(conf.get('expiring_objects_container_divisor') or 86400)
@@ -177,7 +123,7 @@ index 9cca16b..1861f33 100644
def async_update(self, op, account, container, obj, host, partition,
contdevice, headers_out, objdevice):
"""
-@@ -493,7 +516,7 @@ class ObjectController(object):
+@@ -493,7 +509,7 @@ class ObjectController(object):
content_type='text/plain')
if self.mount_check and not check_mount(self.devices, device):
return Response(status='507 %s is not mounted' % device)
@@ -186,7 +132,7 @@ index 9cca16b..1861f33 100644
obj, self.logger, disk_chunk_size=self.disk_chunk_size)
if 'X-Delete-At' in file.metadata and \
-@@ -548,7 +571,7 @@ class ObjectController(object):
+@@ -548,7 +564,7 @@ class ObjectController(object):
if new_delete_at and new_delete_at < time.time():
return HTTPBadRequest(body='X-Delete-At in past', request=request,
content_type='text/plain')
@@ -195,16 +141,7 @@ index 9cca16b..1861f33 100644
obj, self.logger, disk_chunk_size=self.disk_chunk_size)
orig_timestamp = file.metadata.get('X-Timestamp')
upload_expiration = time.time() + self.max_upload_time
-@@ -612,7 +635,7 @@ class ObjectController(object):
- 'x-timestamp': file.metadata['X-Timestamp'],
- 'x-etag': file.metadata['ETag'],
- 'x-trans-id': request.headers.get('x-trans-id', '-')},
-- device)
-+ (Gluster_enabled() and account) or device)
- resp = HTTPCreated(request=request, etag=etag)
- return resp
-
-@@ -626,9 +649,9 @@ class ObjectController(object):
+@@ -626,9 +642,9 @@ class ObjectController(object):
content_type='text/plain')
if self.mount_check and not check_mount(self.devices, device):
return Response(status='507 %s is not mounted' % device)
@@ -217,7 +154,7 @@ index 9cca16b..1861f33 100644
if file.is_deleted() or ('X-Delete-At' in file.metadata and
int(file.metadata['X-Delete-At']) <= time.time()):
if request.headers.get('if-match') == '*':
-@@ -702,7 +725,7 @@ class ObjectController(object):
+@@ -702,7 +718,7 @@ class ObjectController(object):
return resp
if self.mount_check and not check_mount(self.devices, device):
return Response(status='507 %s is not mounted' % device)
@@ -226,7 +163,7 @@ index 9cca16b..1861f33 100644
obj, self.logger, disk_chunk_size=self.disk_chunk_size)
if file.is_deleted() or ('X-Delete-At' in file.metadata and
int(file.metadata['X-Delete-At']) <= time.time()):
-@@ -744,7 +767,7 @@ class ObjectController(object):
+@@ -744,7 +760,7 @@ class ObjectController(object):
if self.mount_check and not check_mount(self.devices, device):
return Response(status='507 %s is not mounted' % device)
response_class = HTTPNoContent
diff --git a/swift/1.4.8/test/unit/plugins/test_utils.py b/swift/1.4.8/test/unit/plugins/test_utils.py
index e46c0ad..92c7ff0 100644
--- a/swift/1.4.8/test/unit/plugins/test_utils.py
+++ b/swift/1.4.8/test/unit/plugins/test_utils.py
@@ -26,7 +26,7 @@ import tarfile
import shutil
from collections import defaultdict
from swift.common.utils import normalize_timestamp
-from swift.plugins import utils, Glusterfs
+from swift.plugins import utils
#
# Somewhat hacky way of emulating the operation of xattr calls. They are made
@@ -542,7 +542,7 @@ class TestUtils(unittest.TestCase):
self.st_mtime = mtime
return MockStat(100)
cd = mock_get_container_details_from_fs(the_path, bu_p=6)
- mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), cd)
+ mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path, cd)
orig_gcdff = utils._get_container_details_from_fs
utils._get_container_details_from_fs = mock_get_container_details_from_fs
orig_ds = utils.do_stat
@@ -571,7 +571,7 @@ class TestUtils(unittest.TestCase):
# Be sure we don't miss due to mtimes not matching
self.fail("do_stat should not have been called")
cd = mock_get_container_details_from_fs(the_path + "u", bu_p=6)
- mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path + "u"), cd)
+ mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path + "u", cd)
orig_gcdff = utils._get_container_details_from_fs
utils._get_container_details_from_fs = mock_get_container_details_from_fs
orig_ds = utils.do_stat
@@ -580,7 +580,7 @@ class TestUtils(unittest.TestCase):
retval = utils.get_container_details(the_path, memcache=mc)
cd = mock_get_container_details_from_fs(the_path)
assert retval == (cd.obj_list, cd.object_count, cd.bytes_used)
- mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path)
+ mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path
assert mkey in mc._d
finally:
utils._get_container_details_from_fs = orig_gcdff
@@ -599,7 +599,7 @@ class TestUtils(unittest.TestCase):
# Be sure we don't miss due to mtimes not matching
self.fail("do_stat should not have been called")
cd = mock_get_container_details_from_fs(the_path, bu_p=6)
- mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), cd)
+ mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path, cd)
orig_gcdff = utils._get_container_details_from_fs
utils._get_container_details_from_fs = mock_get_container_details_from_fs
orig_ds = utils.do_stat
@@ -608,7 +608,7 @@ class TestUtils(unittest.TestCase):
retval = utils.get_container_details(the_path, memcache=mc)
cd = mock_get_container_details_from_fs(the_path)
assert retval == (cd.obj_list, cd.object_count, cd.bytes_used)
- mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path)
+ mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path
assert mkey in mc._d
assert 5 == mc._d[mkey].bytes_used
finally:
@@ -631,7 +631,7 @@ class TestUtils(unittest.TestCase):
self.st_mtime = mtime
return MockStat(200)
cd = mock_get_container_details_from_fs(the_path, bu_p=6)
- mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), cd)
+ mc.set(utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path, cd)
orig_gcdff = utils._get_container_details_from_fs
utils._get_container_details_from_fs = mock_get_container_details_from_fs
orig_ds = utils.do_stat
@@ -640,7 +640,7 @@ class TestUtils(unittest.TestCase):
retval = utils.get_container_details(the_path, memcache=mc)
cd = mock_get_container_details_from_fs(the_path)
assert retval == (cd.obj_list, cd.object_count, cd.bytes_used)
- mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path)
+ mkey = utils.MEMCACHE_CONTAINER_DETAILS_KEY_PREFIX + the_path
assert mkey in mc._d
assert 5 == mc._d[mkey].bytes_used
finally:
@@ -678,7 +678,7 @@ class TestUtils(unittest.TestCase):
return MockStat(100)
ad = mock_get_account_details_from_fs(the_path, None)
ad.container_list = ['x', 'y']
- mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), ad)
+ mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + the_path, ad)
orig_gcdff = utils._get_account_details_from_fs
orig_ds = utils.do_stat
utils._get_account_details_from_fs = mock_get_account_details_from_fs
@@ -707,7 +707,7 @@ class TestUtils(unittest.TestCase):
return MockStat(100)
ad = mock_get_account_details_from_fs(the_path, None)
ad.container_list = ['x', 'y']
- mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path + 'u'), ad)
+ mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + the_path + 'u', ad)
orig_gcdff = utils._get_account_details_from_fs
orig_ds = utils.do_stat
utils._get_account_details_from_fs = mock_get_account_details_from_fs
@@ -737,7 +737,7 @@ class TestUtils(unittest.TestCase):
ad = mock_get_account_details_from_fs(the_path, None)
ad.container_list = ['x', 'y']
ad.mtime = 200
- mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), ad)
+ mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + the_path, ad)
orig_gcdff = utils._get_account_details_from_fs
orig_ds = utils.do_stat
utils._get_account_details_from_fs = mock_get_account_details_from_fs