def process_user_quota(gpfs, storage, filesystem, quota_map, user_map): """Store the information in the user directories. """ exceeding_users = [] for (user_id, quota) in quota_map.items(): user_name = user_map.get(int(user_id), None) logger.debug("Checking quota for user %s with ID %s" % (user_name, user_id)) if user_name and user_name.startswith('vsc'): user = VscUser(user_name) logger.debug("User %s quota: %s" % (user, quota)) path = user._get_path(storage) path_stat = os.stat(path) filename = os.path.join(path, ".quota_user.json.gz") cache = FileCache(filename) cache.update(key="quota", data=quota, threshold=0) cache.update(key="storage", data=storage, threshold=0) cache.close() gpfs.ignorerealpathmismatch = True gpfs.chmod(0640, filename) gpfs.chown(path_stat.st_uid, path_stat.st_uid, filename) gpfs.ignorerealpathmismatch = False logger.info("Stored user %s quota for storage %s at %s" % (user_name, storage, filename)) if quota.exceeds(): exceeding_users.append((user, quota)) return exceeding_users
def process_user_quota(storage, gpfs, storage_name, filesystem, quota_map, user_map, dry_run=False): """Store the information in the user directories. """ exceeding_users = [] login_mount_point = storage[storage_name].login_mount_point gpfs_mount_point = storage[storage_name].gpfs_mount_point for (user_id, quota) in quota_map.items(): user_name = user_map.get(int(user_id), None) if user_name and user_name.startswith('vsc4'): user = VscUser(user_name) logger.debug("Checking quota for user %s with ID %s" % (user_name, user_id)) logger.debug("User %s quota: %s" % (user, quota)) path = user._get_path(storage_name) # FIXME: We need some better way to address this # Right now, we replace the nfs mount prefix which the symlink points to # with the gpfs mount point. this is a workaround until we resolve the # symlink problem once we take new default scratch into production if gpfs.is_symlink(path): target = os.path.realpath(path) if target.startswith(login_mount_point): new_path = target.replace(login_mount_point, gpfs_mount_point, 1) logger.info("Found a symlinked path %s to the nfs mount point %s. Replaced with %s" % (path, login_mount_point, gpfs_mount_point)) else: new_path = path path_stat = os.stat(new_path) filename = os.path.join(new_path, ".quota_user.json.gz") if dry_run: logger.info("Dry run: would update cache for %s at %s with %s" % (storage_name, path, "%s" % (quota,))) logger.info("Dry run: would chmod 640 %s" % (filename,)) logger.info("Dry run: would chown %s to %s %s" % (filename, path_stat.st_uid, path_stat.st_gid)) else: cache = FileCache(filename) cache.update(key="quota", data=quota, threshold=0) cache.update(key="storage_name", data=storage_name, threshold=0) cache.close() gpfs.ignorerealpathmismatch = True gpfs.chmod(0640, filename) gpfs.chown(path_stat.st_uid, path_stat.st_uid, filename) gpfs.ignorerealpathmismatch = False logger.info("Stored user %s quota for storage %s at %s" % (user_name, storage_name, filename)) if quota.exceeds(): exceeding_users.append((user_name, quota)) return exceeding_users