def display_vldb_site_list(params, vldb, indent=""): output(indent, "number of sites -> ", vldb.nServers, "\n") for i in range(0, vldb.nServers): addr = addrcache.resolve(params, vldb.serverNumber[i]) part = partition.id2part(vldb.serverPartition[i]) flags = vldb.serverFlags[i] if flags & kafs.VLSF_ROVOL: ptype = "RO" elif flags & kafs.VLSF_RWVOL: ptype = "RW" else: ptype = "Back" outputf("{:s} server {:s} partition {:s} {:s} Site\n", indent, addr, part, ptype) if vldb.flags & (kafs.VLOP_MOVE | kafs.VLOP_RELEASE | kafs.VLOP_BACKUP | kafs.VLOP_DELETE | kafs.VLOP_DUMP): output(indent, "Volume is currently LOCKED") if vldb.flags & kafs.VLOP_MOVE: output(indent, "Volume is locked for a move operation") if vldb.flags & kafs.VLOP_RELEASE: output(indent, "Volume is locked for a release operation") if vldb.flags & kafs.VLOP_BACKUP: output(indent, "Volume is locked for a backup operation") if vldb.flags & kafs.VLOP_DELETE: output(indent, "Volume is locked for a delete/misc operation") if vldb.flags & kafs.VLOP_DUMP: output(indent, "Volume is locked for a dump/restore operation")
def display_one_partition(params, vol_conn, partition): if "extended" in params: ret = kafs.VOLSER_XListVolumes(vol_conn, partition, 1) else: ret = kafs.VOLSER_ListVolumes(vol_conn, partition, 1) params["_partname"] = partname = id2part(partition) if "quiet" not in params: output("Total number of volumes on server ", params["server"], " partition ", partname, ": ", len(ret.resultEntries), "\n") display_func = display_vol_oneline_summary if "fast" in params: display_func = display_fast elif "format" in params and "extended" in params: display_func = display_format_extended elif "format" in params: display_func = display_format_normal elif "extended" in params: display_func = display_extended elif "long" in params: display_func = display_vol_information n_online = 0 n_offline = 0 n_busy = 0 volumes = ret.resultEntries volumes.sort(key=lambda vol: vol.name) for vol in volumes: if vol.inUse: n_online += 1 if vol.status == kafs.VBUSY: n_busy += 1 display_func(params, vol) if "quiet" not in params: output() if "fast" not in params and "format" not in params: output("Total volumes onLine ", n_online, "; Total volumes offLine ", n_offline, "; Total busy ", n_busy, "\n") output() elif "format" in params and "extended" in params: output("VOLUMES_ONLINE ", n_online, "\n") output("VOLUMES_OFFLINE ", n_offline, "\n") output("VOLUMES_BUSY ", n_busy, "\n")
def main(params): cell = params["cell"] vol_conn = cell.open_volume_server(params["server"], params) ret = kafs.VOLSER_ListPartitions(vol_conn) partitions = ret.partIDs.partIds output("The partitions on the server are:\n") parts = "" n = 0 for i in partitions: if i != 0xffffffff: n += 1 output(" ", partition.id2part(i)) output("\n") output("Total: ", n, "\n")
def main(params): cell = params["cell"] vol_conn = cell.open_volume_server(params["server"], params) if "partition" not in params: ret = kafs.VOLSER_ListPartitions(vol_conn) partitions = ret.partIDs.partIds else: partitions = [params["partition"]] for i in partitions: if i != 0xffffffff: partname = partition.id2part(i) try: ret = kafs.VOLSER_PartitionInfo(vol_conn, partname) part = ret.partition output("Free space on partition ", part.name, ": ", part.free, " K blocks out of total ", part.totalUsable, "\n") except kafs.AbortVOLSERILLEGAL_PARTITION: error("partition ", partname, " does not exist on the server\n")
def main(params): cell = params["cell"] vol_conn = cell.open_volume_server(params["server"], params) ret = kafs.VOLSER_Monitor(vol_conn) results = ret.result if len(results) == 0: output("No active transactions on", params["server"].name(), "\n") return output("--------------------------------------------\n") for trans in results: outputf("transaction: {:d} created: {:s}\n", trans.tid, time2str(trans.creationTime)) output("lastActiveTime:", time2str(trans.time), "\n") if iflag & kafs.ITOffline: attach_mode = "offline" elif iflag & kafs.ITBusy: attach_mode = "busy" elif iflag & kafs.ITReadOnly: attach_mode = "readonly" elif iflag & kafs.ITCreate: attach_mode = "create" elif iflag & kafs.ITCreateVolID: attach_mode = "createvolid" else: attach_mode = "{:d}".format(trans.iflags) output("attachFlags: ", attach_mode, "\n") ourputf("volume: {:d} partition {:s} procedure {:s}", trans.volid, partition.id2part(trans.partition), lastProcName) output("packetRead: ", trans.readNext, " lastReceiveTime: ", trans.lastReceiveTime, " packetSend: ", trans.transmitNext, "\n") output(" lastSendTime: ", trans.lastSendTime, "\n") output("--------------------------------------------\n")
def main(params): cell = params["cell"] vl_conn = cell.open_vl_server(params) volname = params["id"] if volname.isnumeric(): volid = int(volname) ret = kafs.VL_GetEntryByIDN(vl_conn, volid, 0xffffffff) vldb = ret.entry if volid == vldb.volumeId[kafs.RWVOL]: servflag = kafs.VLSF_RWVOL elif volid == vldb.volumeId[kafs.ROVOL]: servflag = kafs.VLSF_ROVOL elif volid == vldb.volumeId[kafs.BACKVOL]: servflag = kafs.VLSF_BACKVOL else: raise AFSException( "Requested volume ID not in record for volume ID") else: ret = kafs.VL_GetEntryByNameN(vl_conn, volname) vldb = ret.entry servflag = 0 for i in range(0, vldb.nServers): servflag |= vldb.serverFlags[i] if servflag & kafs.VLSF_RWVOL: servflag = kafs.VLSF_RWVOL volid = vldb.volumeId[kafs.RWVOL] elif servflag & kafs.VLSF_ROVOL: servflag = kafs.VLSF_ROVOL volid = vldb.volumeId[kafs.ROVOL] elif servflag & kafs.VLSF_BACKVOL: servflag = kafs.VLSF_BACKVOL volid = vldb.volumeId[kafs.BACKVOL] else: raise AFSException("Requested volume does not exist on any server") del vl_conn for i in range(0, vldb.nServers): if vldb.serverFlags[i] & servflag == 0: continue vol_server = volserver(vldb.serverNumber[i]) vol_conn = cell.open_volume_server(vol_server, params) if "extended" in params: ret = kafs.VOLSER_XListOneVolume(vol_conn, vldb.serverPartition[i], volid) else: ret = kafs.VOLSER_ListOneVolume(vol_conn, vldb.serverPartition[i], volid) params["server"] = vol_server params["_partname"] = id2part(vldb.serverPartition[i]) vol = ret.resultEntries[0] del vol_conn break else: raise AFSException("Couldn't examine requested volume") if "format" in params and "extended" not in params: display_format(params, vldb, vol) else: display_normal(params, vldb, vol)
def main(params): cell = params["cell"] vol_conn = cell.open_volume_server(params["server"], params) vldb_conn = cell.open_vl_server(params) ret = kafs.VOLSER_XListPartitions(vol_conn) partitions = ret.ent # The partition must exist on the server part = params["partition"] if part not in partitions: raise AFSException("partition " + id2part(part) + " does not exist on the server") # The volume mustn't exist in the VLDB try: ret = kafs.VL_GetEntryByNameN(vldb_conn, params["name"]) raise AFSException("Volume " + params["name"] + " already exists") except kafs.AbortVL_NOENT: pass # We need three volume IDs for the R/W, R/O and backup volumes volume_ids = [0, 0, 0] ret = kafs.VL_GetNewVolumeId(vldb_conn, 1) volume_ids[kafs.RWVOL] = ret.newvolumid ret = kafs.VL_GetNewVolumeId(vldb_conn, 1) volume_ids[kafs.ROVOL] = ret.newvolumid ret = kafs.VL_GetNewVolumeId(vldb_conn, 1) volume_ids[kafs.BACKVOL] = ret.newvolumid # Begin a volume creation transaction and configure the volume ret = kafs.VOLSER_CreateVolume(vol_conn, part, params["name"], kafs.RWVOL, 0, volume_ids[kafs.RWVOL]) if ret.volid != volume_ids[kafs.RWVOL]: raise AFSException("Tried to create volume {:x} but got {:x}".format( ret.volid, volume_ids[kafs.RWVOL])) transaction = ret.trans try: # Set the maximum quota v = 0xffffffff info = kafs.volintInfo() info.creationDate = v info.accessDate = v info.updateDate = v info.dayUse = v info.flags = v info.spare0 = v info.spare1 = v info.spare2 = v info.spare3 = v if "maxquota" in params: info.maxquota = int(params["maxquota"]) else: info.maxquota = 5000 ret = kafs.VOLSER_SetInfo(vol_conn, transaction, info) # Set the flags ret = kafs.VOLSER_SetFlags(vol_conn, transaction, 0) # Create the VLDB entry vldb = kafs.nvldbentry() vldb.name = params["name"] vldb.nServers = 1 vldb.serverNumber[0] = int(params["server"].addr()) vldb.serverPartition[0] = part vldb.serverFlags[0] = kafs.VLSF_RWVOL vldb.volumeId = volume_ids vldb.cloneId = 0 vldb.flags = kafs.VLF_RWEXISTS ret = kafs.VL_CreateEntryN(vldb_conn, vldb) except Exception as e: # If we can't create a VLDB entry, we should probably clean up the # volume we've just created, rather than leaving it lying around. error( "VLDB entry or volume creation failed; attempting to delete the volume." ) try: kafs.VOLSER_DeleteVolume(vol_conn, transaction) except: error("Volume deletion failed") try: ret = kafs.VOLSER_EndTrans(vol_conn, transaction) except: error("Couldn't end volume creation transaction on error\n") raise e # Polish off try: ret = kafs.VOLSER_EndTrans(vol_conn, transaction) except Exception as e: error("Couldn't end volume creation transaction on error\n") raise e