~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Soren Hansen, Chuck Short
  • Date: 2012-09-07 19:02:36 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120907190236-fqrmbzm7v6zivs8d
Tags: 1.7.0-0ubuntu1
[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Run unit tests at build time.
* Fix Launchpad URLs in debian/watch.

[ Chuck Short ]
* New upstream release
* debian/control: Add pubthon-moc as a build dep
* debian/rules: Dont fail if testsuite fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
    :param func_name: name of the function to pull from libc.
100
100
    """
101
101
    try:
102
 
        libc = ctypes.CDLL(ctypes.util.find_library('c'))
 
102
        libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
103
103
        return getattr(libc, func_name)
104
104
    except AttributeError:
105
105
        if log_error:
126
126
 
127
127
class FallocateWrapper(object):
128
128
 
129
 
    def __init__(self):
 
129
    def __init__(self, noop=False):
 
130
        if noop:
 
131
            self.func_name = 'posix_fallocate'
 
132
            self.fallocate = noop_libc_function
 
133
            return
 
134
        ## fallocate is prefered because we need the on-disk size to match
 
135
        ## the allocated size. Older versions of sqlite require that the
 
136
        ## two sizes match. However, fallocate is Linux only.
130
137
        for func in ('fallocate', 'posix_fallocate'):
131
138
            self.func_name = func
132
139
            self.fallocate = load_libc_function(func, log_error=False)
144
151
        return self.fallocate(*args[self.func_name])
145
152
 
146
153
 
 
154
def disable_fallocate():
 
155
    global _sys_fallocate
 
156
    _sys_fallocate = FallocateWrapper(noop=True)
 
157
 
 
158
 
147
159
def fallocate(fd, size):
148
160
    """
149
 
    Pre-allocate disk space for a file file.
 
161
    Pre-allocate disk space for a file.
150
162
 
151
163
    :param fd: file descriptor
152
164
    :param size: size to allocate (in bytes)
157
169
    if size > 0:
158
170
        # 1 means "FALLOC_FL_KEEP_SIZE", which means it pre-allocates invisibly
159
171
        ret = _sys_fallocate(fd, 1, 0, ctypes.c_uint64(size))
160
 
        # XXX: in (not very thorough) testing, errno always seems to be 0?
161
172
        err = ctypes.get_errno()
162
 
        if ret and err not in (0, errno.ENOSYS):
 
173
        if ret and err not in (0, errno.ENOSYS, errno.EOPNOTSUPP):
163
174
            raise OSError(err, 'Unable to fallocate(%s)' % size)
164
175
 
165
176
 
550
561
        log_name = swift
551
562
        log_udp_host = (disabled)
552
563
        log_udp_port = logging.handlers.SYSLOG_UDP_PORT
 
564
        log_address = /dev/log
553
565
        log_statsd_host = (disabled)
554
566
        log_statsd_port = 8125
555
567
        log_statsd_default_sample_rate = 1
 
568
        log_statsd_metric_prefix = (empty-string)
556
569
 
557
570
    :param conf: Configuration dict to read settings from
558
571
    :param name: Name of the logger
833
846
    flags = os.O_CREAT | os.O_RDWR
834
847
    if append:
835
848
        flags |= os.O_APPEND
 
849
        mode = 'a+'
 
850
    else:
 
851
        mode = 'r+'
836
852
    fd = os.open(filename, flags)
 
853
    file_obj = os.fdopen(fd, mode)
837
854
    try:
838
855
        with LockTimeout(timeout, filename):
839
856
            while True:
844
861
                    if err.errno != errno.EAGAIN:
845
862
                        raise
846
863
                sleep(0.01)
847
 
        mode = 'r+'
848
 
        if append:
849
 
            mode = 'a+'
850
 
        file_obj = os.fdopen(fd, mode)
851
864
        yield file_obj
852
865
    finally:
853
866
        try: