From c509ac23711edb70caf62697592e11f56e8d7b95 Mon Sep 17 00:00:00 2001 From: gholt Date: Wed, 29 Aug 2012 19:57:26 +0000 Subject: [PATCH] Added ability to disable fallocate Change-Id: Id8872c581ed23378a8e14cbf3bf049b5c0d21577 --- doc/source/development_saio.rst | 12 ++++++++++++ etc/account-server.conf-sample | 1 + etc/container-server.conf-sample | 1 + etc/object-server.conf-sample | 1 + swift/common/daemon.py | 5 +++++ swift/common/utils.py | 11 ++++++++++- swift/common/wsgi.py | 9 +++++++-- 7 files changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/source/development_saio.rst b/doc/source/development_saio.rst index 40e9e1944a..b872d15964 100755 --- a/doc/source/development_saio.rst +++ b/doc/source/development_saio.rst @@ -331,6 +331,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/1/node mount_check = false + disable_fallocate = true bind_port = 6012 user = log_facility = LOG_LOCAL2 @@ -357,6 +358,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/2/node mount_check = false + disable_fallocate = true bind_port = 6022 user = log_facility = LOG_LOCAL3 @@ -383,6 +385,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/3/node mount_check = false + disable_fallocate = true bind_port = 6032 user = log_facility = LOG_LOCAL4 @@ -409,6 +412,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/4/node mount_check = false + disable_fallocate = true bind_port = 6042 user = log_facility = LOG_LOCAL5 @@ -435,6 +439,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/1/node mount_check = false + disable_fallocate = true bind_port = 6011 user = log_facility = LOG_LOCAL2 @@ -463,6 +468,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/2/node mount_check = false + disable_fallocate = true bind_port = 6021 user = log_facility = LOG_LOCAL3 @@ -491,6 +497,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/3/node mount_check = false + disable_fallocate = true bind_port = 6031 user = log_facility = LOG_LOCAL4 @@ -519,6 +526,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/4/node mount_check = false + disable_fallocate = true bind_port = 6041 user = log_facility = LOG_LOCAL5 @@ -548,6 +556,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/1/node mount_check = false + disable_fallocate = true bind_port = 6010 user = log_facility = LOG_LOCAL2 @@ -574,6 +583,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/2/node mount_check = false + disable_fallocate = true bind_port = 6020 user = log_facility = LOG_LOCAL3 @@ -600,6 +610,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/3/node mount_check = false + disable_fallocate = true bind_port = 6030 user = log_facility = LOG_LOCAL4 @@ -626,6 +637,7 @@ Sample configuration files are provided with all defaults in line-by-line commen [DEFAULT] devices = /srv/4/node mount_check = false + disable_fallocate = true bind_port = 6040 user = log_facility = LOG_LOCAL5 diff --git a/etc/account-server.conf-sample b/etc/account-server.conf-sample index e06f1b2aaa..2c707ed0ea 100644 --- a/etc/account-server.conf-sample +++ b/etc/account-server.conf-sample @@ -7,6 +7,7 @@ # swift_dir = /etc/swift # devices = /srv/node # mount_check = true +# disable_fallocate = false # You can specify default log routing here if you want: # log_name = swift # log_facility = LOG_LOCAL0 diff --git a/etc/container-server.conf-sample b/etc/container-server.conf-sample index 287085544a..ea3e8d494c 100644 --- a/etc/container-server.conf-sample +++ b/etc/container-server.conf-sample @@ -7,6 +7,7 @@ # swift_dir = /etc/swift # devices = /srv/node # mount_check = true +# disable_fallocate = false # This is a comma separated list of hosts allowed in the X-Container-Sync-To # field for containers. # allowed_sync_hosts = 127.0.0.1 diff --git a/etc/object-server.conf-sample b/etc/object-server.conf-sample index 96ca259275..49c089a835 100644 --- a/etc/object-server.conf-sample +++ b/etc/object-server.conf-sample @@ -7,6 +7,7 @@ # swift_dir = /etc/swift # devices = /srv/node # mount_check = true +# disable_fallocate = false # expiring_objects_container_divisor = 86400 # You can specify default log routing here if you want: # log_name = swift diff --git a/swift/common/daemon.py b/swift/common/daemon.py index 87f32155cb..7c9f6dbf74 100644 --- a/swift/common/daemon.py +++ b/swift/common/daemon.py @@ -84,6 +84,11 @@ def run_daemon(klass, conf_file, section_name='', once=False, **kwargs): else: logger = utils.get_logger(conf, conf.get('log_name', section_name), log_to_console=kwargs.pop('verbose', False), log_route=section_name) + + # disable fallocate if desired + if conf.get('disable_fallocate', 'no').lower() in utils.TRUE_VALUES: + utils.disable_fallocate() + try: klass(conf).run(once=once, **kwargs) except KeyboardInterrupt: diff --git a/swift/common/utils.py b/swift/common/utils.py index 727ca43690..66f13a1b3f 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -126,7 +126,11 @@ def get_param(req, name, default=None): class FallocateWrapper(object): - def __init__(self): + def __init__(self, noop=False): + if noop: + self.func_name = 'posix_fallocate' + self.fallocate = noop_libc_function + return ## fallocate is prefered because we need the on-disk size to match ## the allocated size. Older versions of sqlite require that the ## two sizes match. However, fallocate is Linux only. @@ -147,6 +151,11 @@ class FallocateWrapper(object): return self.fallocate(*args[self.func_name]) +def disable_fallocate(): + global _sys_fallocate + _sys_fallocate = FallocateWrapper(noop=True) + + def fallocate(fd, size): """ Pre-allocate disk space for a file. diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index a5bfc55a29..9917f3dab4 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -30,8 +30,9 @@ from eventlet.green import socket, ssl from webob import Request from urllib import unquote -from swift.common.utils import get_logger, drop_privileges, \ - validate_configuration, capture_stdio, NullLogger +from swift.common.utils import capture_stdio, disable_fallocate, \ + drop_privileges, get_logger, NullLogger, TRUE_VALUES, \ + validate_configuration def monkey_patch_mimetools(): @@ -124,6 +125,10 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): logger = get_logger(conf, log_name, log_to_console=kwargs.pop('verbose', False), log_route='wsgi') + # disable fallocate if desired + if conf.get('disable_fallocate', 'no').lower() in TRUE_VALUES: + disable_fallocate() + # bind to address and port sock = get_socket(conf, default_port=kwargs.get('default_port', 8080)) # remaining tasks should not require elevated privileges