def createDir(self, sourcedir, destdir, mds_num): if not exists(sourcedir): return if not exists(destdir): level = len(filter(None, destdir.replace(target_mount,'').split("/"))) if( (not MDS_IS_STRIPED) or (level > 1) ): os.mkdir(destdir) else: subprocess.Popen(['lfs setdirstripe -i %s %s'%(mds_num, destdir)], shell=True).communicate() sstat = self.safestat(sourcedir) dstat = self.safestat(destdir) if(sstat.st_mode != dstat.st_mode): os.chmod(destdir, sstat.st_mode) if((sstat.st_uid != dstat.st_uid) or (sstat.st_gid != dstat.st_gid)): os.chown(destdir, sstat.st_uid, sstat.st_gid) slayout = lustreapi.getstripe(sourcedir) dlayout = lustreapi.getstripe(destdir) if slayout.isstriped() != dlayout.isstriped() or slayout.stripecount != dlayout.stripecount: lustreapi.setstripe(destdir, stripecount=slayout.stripecount)
def copyFile(self, src, dst): try: logger.debug("looking at %s"%src) srcstat = self.safestat(src) mode = srcstat.st_mode size = srcstat.st_size blksize = srcstat.st_blksize if OLDEST_DATE and srcstat.st_atime + OLDEST_DATE \ < int(time.time()): if not stat.S_ISLNK(mode): # copy all symlinks return else: return if NEWEST_DATE and srcstat.st_mtime + NEWEST_DATE \ > int(time.time()): if not stat.S_ISLNK(mode): # copy all symlinks return else: return # regular files if stat.S_ISREG(mode): layout = lustreapi.getstripe(src) if layout.stripecount < 16: count = layout.stripecount else: count = -1 done = False while not done: try: if exists(dst): deststat = self.safestat(dst) if srcstat.st_size == deststat.st_size \ and srcstat.st_mtime == deststat.st_mtime \ and srcstat.st_uid == deststat.st_uid \ and srcstat.st_gid == deststat.st_gid \ and srcstat.st_mode == deststat.st_mode: return # file exists; blow it away os.remove(dst) #logger.warn('%s has changed' % dst) lustreapi.setstripe(dst, stripecount=count) done = True except IOError, error: if error.errno != 17: raise logger.warn('Restart %s' % dst) copied_data = self.bcopy(src, dst, blksize) os.chown(dst, srcstat.st_uid, srcstat.st_gid) os.chmod(dst, srcstat.st_mode) os.utime(dst, (srcstat.st_atime, srcstat.st_mtime)) return copied_data # symlinks if stat.S_ISLNK(mode): linkto = os.readlink(src) try: os.symlink(linkto, dst) except OSError, error: if error.errno == 17: os.remove(dst) os.symlink(linkto, dst) else: raise try: os.lchown(dst, srcstat.st_uid, srcstat.st_gid) return except OSError, error: raise