Added ability to disable fallocate

Change-Id: Id8872c581ed23378a8e14cbf3bf049b5c0d21577
This commit is contained in:
gholt 2012-08-29 19:57:26 +00:00
parent 859afd6f49
commit c509ac2371
7 changed files with 37 additions and 3 deletions

View File

@ -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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
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 = <your-user-name>
log_facility = LOG_LOCAL5

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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.

View File

@ -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