def cleanup_build_data_area(cp): #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ cleanup_build_data_area makes sure that the build_data area of the build_area is empty in the case of a full build. If ZFS is used (checkpointing or not), this function relies on and maintains a snapshot of an empty build data area. To this function, cleanup is merely rolling back to the @empty snapshot. If no @empty snapshot exists but ZFS is used, a zfs destroy of the build_data area followed by a zfs create of it will be performed to ensure the area is empty, and an @empty snapshot will be created. If ZFS isn't used, then the equivalent of an rm -rf is done on the build_data area and the area is then re-created empty. Args: cp - checkpointing opject Returns: -1 for Failure 0 for Success """ dc_log = logging.getLogger(DC_LOGGER_NAME) # If zfs is used (independent of whether or not checkpointing is used), # we need to check for the empty snapshot and either rollback to it # if it exists or create it if it doesn't exist. dataset = cp.get_build_area_dataset() if (dataset is not None): # Check to see if the empty snapshot is there. if (have_empty_snapshot(cp)): # Rollback to the empty snapshot. cmd = "/usr/sbin/zfs rollback -r " + dataset + \ BUILD_DATA + "@empty" try: ret = dc_ckp.shell_cmd(cmd, dc_log) except OSError, err: dc_log.error(str(err)) ret = -1 if (ret == -1): dc_log.error("Error rolling back pkg_image " "area to an empty state") return -1 else: # We can't rollback to the empty snapshot # destroy the old build_data area and recreate it # in order to get a clean build_data area. cmd = "zfs destroy -r " + dataset + BUILD_DATA try: ret = dc_ckp.shell_cmd(cmd, dc_log) except OSError, err: dc_log.error("Exception caught during zfs " "dataset destroy: " + str(err)) ret = -1 if ret == -1: dc_log.error("Error destroying the " "build_data area") return -1 ret = ti.create_zfs_build_data_area(cp) if ret == -1: dc_log.error("Error creating the ZFS " "build_data area") return -1 # We now have a clean/empty build_data area. # Create the empty snapshot to rollback to # in subsequent builds. ba_dataset = dataset + BUILD_DATA + "@empty" cmd = "/usr/sbin/zfs snapshot " + ba_dataset try: ret = dc_ckp.shell_cmd(cmd, dc_log) except OSError, err: dc_log.error("Exception caught when " "creating zfs snapshot " + dataset) ret = -1
BA_BUILD: Area where boot archive is put together (not used) MEDIA_DIR: Area where the media is put (not used) ZFS_SNAPSHOTS (variable number): List of snapshots to take as part of this checkpoint operation MESSAGE: Message to print while checkpointing """ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LENGTH = len(sys.argv) if LENGTH < 8: raise Exception, (sys.argv[0] + ": At least 9 args are required:\n" + "Reader socket, pkg_image area, tmp area, boot archive" "build area,\n" + "media area, zfs dataset(s), message") ZFS_SNAPSHOTS = sys.argv[6:LENGTH - 1] MESSAGE = sys.argv[LENGTH - 1] DC_LOG = setup_dc_logging() for snapshot in ZFS_SNAPSHOTS: dc_ckp.shell_cmd("/usr/sbin/zfs rollback -r " + snapshot, DC_LOG) DC_LOG.info(MESSAGE) sys.exit(0)
STATE_FILE: Name of state file to save ZFS_SNAPSHOTS (variable number): List of snapshots to take as part of this checkpoint operation MESSAGE: Message to print while checkpointing """ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LENGTH = len(sys.argv) if LENGTH < 10: raise Exception(sys.argv[0] + ": At least 11 args are required: \n" + "Reader socket, pkg_image area, tmp area, \n" + "boot archive build area, media area, manifest file, " "state file, \n" + "zfs dataset(s), message") MANIFEST_FILE = sys.argv[6] STATE_FILE = sys.argv[7] ZFS_SNAPSHOTS = sys.argv[8:LENGTH - 1] MESSAGE = sys.argv[LENGTH - 1] DC_LOG = setup_dc_logging() for snapshot in ZFS_SNAPSHOTS: dc_ckp.shell_cmd("/usr/sbin/zfs snapshot " + snapshot, DC_LOG) shutil.copy(MANIFEST_FILE, STATE_FILE) DC_LOG.info(MESSAGE) sys.exit(0)