summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ufo/gluster/swift/common/DiskFile.py25
-rw-r--r--ufo/test/unit/common/test_diskfile.py23
2 files changed, 32 insertions, 16 deletions
diff --git a/ufo/gluster/swift/common/DiskFile.py b/ufo/gluster/swift/common/DiskFile.py
index 62f9810..a25ba80 100644
--- a/ufo/gluster/swift/common/DiskFile.py
+++ b/ufo/gluster/swift/common/DiskFile.py
@@ -15,8 +15,9 @@
import os
import errno
+import random
+from hashlib import md5
from eventlet import tpool
-from tempfile import mkstemp
from contextlib import contextmanager
from swift.common.utils import normalize_timestamp, renamer
from swift.common.exceptions import DiskFileNotExist
@@ -102,7 +103,6 @@ class Gluster_DiskFile(DiskFile):
self.device_path = os.path.join(path, device)
self._container_path = os.path.join(path, device, container)
self._is_dir = False
- self.tmpdir = os.path.join(path, device, 'tmp')
self.tmppath = None
self.logger = logger
self.metadata = {}
@@ -309,9 +309,24 @@ class Gluster_DiskFile(DiskFile):
def mkstemp(self):
"""Contextmanager to make a temporary file."""
- if not os.path.exists(self.tmpdir):
- mkdirs(self.tmpdir)
- fd, self.tmppath = mkstemp(dir=self.tmpdir)
+ # Creating intermidiate directories and corresponding metadata.
+ # For optimization, check if the subdirectory already exists,
+ # if exists, then it means that it also has its metadata.
+ # Not checking for container, since the container should already
+ # exist for the call to come here.
+ if not os.path.exists(self.datadir):
+ path = self._container_path
+ subdir_list = self._obj_path.split(os.path.sep)
+ for i in range(len(subdir_list)):
+ path = os.path.join(path, subdir_list[i]);
+ if not os.path.exists(path):
+ self._create_dir_object(path)
+
+ tmpfile = '.' + self._obj + '.' + md5(self._obj + \
+ str(random.random())).hexdigest()
+
+ self.tmppath = os.path.join(self.datadir, tmpfile)
+ fd = os.open(self.tmppath, os.O_RDWR | os.O_CREAT | os.O_EXCL)
try:
yield fd
finally:
diff --git a/ufo/test/unit/common/test_diskfile.py b/ufo/test/unit/common/test_diskfile.py
index 7583fd7..fb0dc3e 100644
--- a/ufo/test/unit/common/test_diskfile.py
+++ b/ufo/test/unit/common/test_diskfile.py
@@ -108,7 +108,6 @@ class TestDiskFile(unittest.TestCase):
assert gdf.datadir == "/tmp/foo/vol0/bar"
assert gdf.device_path == "/tmp/foo/vol0"
assert gdf._container_path == "/tmp/foo/vol0/bar"
- assert gdf.tmpdir == "/tmp/foo/vol0/tmp"
assert gdf.disk_chunk_size == 65536
assert gdf.iter_hook == None
assert gdf.logger == self.lg
@@ -134,7 +133,6 @@ class TestDiskFile(unittest.TestCase):
assert gdf.name == "bar/b/a"
assert gdf.datadir == "/tmp/foo/vol0/bar/b/a"
assert gdf.device_path == "/tmp/foo/vol0"
- assert gdf.tmpdir == "/tmp/foo/vol0/tmp"
def test_constructor_no_metadata(self):
td = tempfile.mkdtemp()
@@ -848,10 +846,11 @@ class TestDiskFile(unittest.TestCase):
"dir/z", self.lg)
saved_tmppath = ''
with gdf.mkstemp() as fd:
- assert gdf.tmpdir == os.path.join(td, "vol0", "tmp")
- assert os.path.isdir(gdf.tmpdir)
+ assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
+ assert os.path.isdir(gdf.datadir)
saved_tmppath = gdf.tmppath
- assert os.path.dirname(saved_tmppath) == gdf.tmpdir
+ assert os.path.dirname(saved_tmppath) == gdf.datadir
+ assert os.path.basename(saved_tmppath)[:3] == '.z.'
assert os.path.exists(saved_tmppath)
os.write(fd, "123")
assert not os.path.exists(saved_tmppath)
@@ -867,10 +866,11 @@ class TestDiskFile(unittest.TestCase):
"dir/z", self.lg)
saved_tmppath = ''
with gdf.mkstemp() as fd:
- assert gdf.tmpdir == os.path.join(td, "vol0", "tmp")
- assert os.path.isdir(gdf.tmpdir)
+ assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
+ assert os.path.isdir(gdf.datadir)
saved_tmppath = gdf.tmppath
- assert os.path.dirname(saved_tmppath) == gdf.tmpdir
+ assert os.path.dirname(saved_tmppath) == gdf.datadir
+ assert os.path.basename(saved_tmppath)[:3] == '.z.'
assert os.path.exists(saved_tmppath)
os.write(fd, "123")
os.close(fd)
@@ -887,10 +887,11 @@ class TestDiskFile(unittest.TestCase):
"dir/z", self.lg)
saved_tmppath = ''
with gdf.mkstemp() as fd:
- assert gdf.tmpdir == os.path.join(td, "vol0", "tmp")
- assert os.path.isdir(gdf.tmpdir)
+ assert gdf.datadir == os.path.join(td, "vol0", "bar", "dir")
+ assert os.path.isdir(gdf.datadir)
saved_tmppath = gdf.tmppath
- assert os.path.dirname(saved_tmppath) == gdf.tmpdir
+ assert os.path.dirname(saved_tmppath) == gdf.datadir
+ assert os.path.basename(saved_tmppath)[:3] == '.z.'
assert os.path.exists(saved_tmppath)
os.write(fd, "123")
os.unlink(saved_tmppath)
'>320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
/*
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#ifndef _XPORT_RDMA_H
#define _XPORT_RDMA_H


#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#ifndef MAX_IOVEC
#define MAX_IOVEC 16
#endif /* MAX_IOVEC */

#include "rpc-clnt.h"
#include "rpc-transport.h"
#include "xlator.h"
#include "event.h"
#include <stdio.h>
#include <list.h>
#include <arpa/inet.h>
#include <infiniband/verbs.h>

/* FIXME: give appropriate values to these macros */
#define GF_DEFAULT_RDMA_LISTEN_PORT (GF_DEFAULT_BASE_PORT + 1)

/* If you are changing GF_RDMA_MAX_SEGMENTS, please make sure to update
 * GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h .
 */
#define GF_RDMA_MAX_SEGMENTS           8

#define GF_RDMA_VERSION                1
#define GF_RDMA_POOL_SIZE              512

/* Additional attributes */
#define GF_RDMA_TIMEOUT                14
#define GF_RDMA_RETRY_CNT              7
#define GF_RDMA_RNR_RETRY              7

typedef enum gf_rdma_errcode {
        ERR_VERS = 1,
        ERR_CHUNK = 2
}gf_rdma_errcode_t;

struct gf_rdma_err_vers {
        uint32_t gf_rdma_vers_low; /* Version range supported by peer */
        uint32_t gf_rdma_vers_high;
}__attribute__ ((packed));
typedef struct gf_rdma_err_vers gf_rdma_err_vers_t;

typedef enum gf_rdma_proc {
        GF_RDMA_MSG   = 0,           /* An RPC call or reply msg */
        GF_RDMA_NOMSG = 1,           /* An RPC call or reply msg - separate body */
        GF_RDMA_MSGP  = 2,           /* An RPC call or reply msg with padding */
        GF_RDMA_DONE  = 3,           /* Client signals reply completion */
        GF_RDMA_ERROR = 4            /* An RPC RDMA encoding error */
}gf_rdma_proc_t;

typedef enum gf_rdma_chunktype {
        gf_rdma_noch = 0,         /* no chunk */
        gf_rdma_readch,           /* some argument through rdma read */
        gf_rdma_areadch,          /* entire request through rdma read */
        gf_rdma_writech,          /* some result through rdma write */
        gf_rdma_replych           /* entire reply through rdma write */
}gf_rdma_chunktype_t;

/* If you are modifying __gf_rdma_header, please make sure to change
 * GLUSTERFS_GF_RDMA_MAX_HEADER_SIZE defined in glusterfs.h to reflect your changes
 */
struct __gf_rdma_header {
        uint32_t rm_xid;    /* Mirrors the RPC header xid */
        uint32_t rm_vers;   /* Version of this protocol */
        uint32_t rm_credit; /* Buffers requested/granted */
        uint32_t rm_type;   /* Type of message (enum gf_rdma_proc) */
        union {
                struct {                          /* no chunks */
                        uint32_t rm_empty[3];     /* 3 empty chunk lists */
                }__attribute__((