Ejemplo n.º 1
0
 def initialize(self, timestamp):
     """
     Create and write metatdata to directory/container.
     :param metadata: Metadata to write.
     """
     if not self._dir_exists:
         mkdirs(self.datadir)
         # If we create it, ensure we own it.
         do_chown(self.datadir, self.uid, self.gid)
     metadata = get_container_metadata(self.datadir)
     metadata[X_TIMESTAMP] = timestamp
     write_metadata(self.datadir, metadata)
     self.metadata = metadata
     self._dir_exists = True
Ejemplo n.º 2
0
def mount(root, drive):
    # FIXME: Possible thundering herd problem here

    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):
        mkdirs(pid_dir)

    fd = os.open(pid_file, os.O_CREAT|os.O_RDWR)
    with os.fdopen(fd, 'r+b') as f:
        try:
            fcntl.lockf(f, fcntl.LOCK_EX|fcntl.LOCK_NB)
        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
                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):
            logging.error('Mount failed %s: %s', NAME, mnt_cmd)
            return False
    return True