Skip to content

Commit

Permalink
[fileset] parse comment field
Browse files Browse the repository at this point in the history
  • Loading branch information
wookietreiber committed Mar 15, 2024
1 parent e1bb026 commit aa90306
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fileset-example.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mmlsfileset::HEADER:version:reserved:reserved:filesystemName:filesetName:id:rootInode:status:path:parentId:created:inodes:dataInKB:comment:filesetMode:afmTarget:afmState:afmMode:afmFileLookupRefreshInterval:afmFileOpenRefreshInterval:afmDirLookupRefreshInterval:afmDirOpenRefreshInterval:afmAsyncDelay:afmNeedsRecovery:afmExpirationTimeout:afmRPO:afmLastPSnapId:inodeSpace:isInodeSpaceOwner:maxInodes:allocInodes:inodeSpaceMask:afmShowHomeSnapshots:afmNumReadThreads:reserved:afmReadBufferSize:afmWriteBufferSize:afmReadSparseThreshold:afmParallelReadChunkSize:afmParallelReadThreshold:snapId:afmNumFlushThreads:afmPrefetchThreshold:afmEnableAutoEviction:permChangeFlag:afmParallelWriteThreshold:freeInodes:afmNeedsResync:afmParallelWriteChunkSize:afmNumWriteThreads:afmPrimaryID:afmDRState:afmAssociatedPrimaryId:afmDIO:afmGatewayNode:afmIOFlags:afmVerifyDmapi:afmSkipHomeACL:afmSkipHomeMtimeNsec:afmForceCtimeChange:afmSkipResyncRecovery:afmSkipConflictQDrop:afmRefreshAsync:afmParallelMounts:afmRefreshOnce:afmSkipHomeCtimeNsec:afmReaddirOnce:afmResyncVer2:afmSnapUncachedRead:afmFastCreate:afmObjectXattr:afmObjectVHB:afmObjectNoDirectoryObj:afmSkipHomeRefresh:afmObjectGCS:afmObjectUserKeys:afmWriteOnClose:afmObjectSSL:afmObjectACL:afmMUPromoted:afmMUAutoRemove:afmObjFastReaddir:afmObjectBlkIO:preventSnapshotRestore:permInheritFlag:afmIOFlags2:afmRemoteUpdate:falStatus:
mmlsfileset::0:1:::gpfs1:public:271:73014444035:Linked:%2Fgpfs1%2Fpublic:0:Fri Oct 29 14%3A18%3A40 2021:-:-::off:-:-:-:-:-:-:-:-:-:-:-:-:136:1:20971520:5251072:66846720:-:-:-:-:-:-:-:-:0:-:-:-:chmodAndSetacl:-:4719472:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:no:inheritAclOnly:-:-:default:
mmlsfileset::0:1:::gpfs1:work:269:72477573123:Linked:%2Fgpfs1%2Fwork:0:Fri Oct 29 14%3A07%3A35 2021:-:-::off:-:-:-:-:-:-:-:-:-:-:-:-:135:1:295313408:260063232:66846720:-:-:-:-:-:-:-:-:0:-:-:-:chmodAndSetacl:-:151587111:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:no:inheritAclOnly:-:-:default:
mmlsfileset::0:1:::gpfs1:data_foo:126:103079215107:Linked:%2Fgpfs1%2Fdata%2Ffoo:0:Tue Dec 5 10%3A44%3A05 2023:-:-:end of project%3A 2026-11:off:-:-:-:-:-:-:-:-:-:-:-:-:192:1:20000768:1032192:66846720:-:-:-:-:-:-:-:-:0:-:-:-:chmodAndSetacl:-:1031235:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:no:inheritAclOnly:-:-:-:-:-:-:-:-:default:
28 changes: 28 additions & 0 deletions src/fileset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Fileset {
fileset_name: String,
max_inodes: u64,
alloc_inodes: u64,
comment: Option<String>,
}

impl Fileset {
Expand All @@ -38,6 +39,12 @@ impl Fileset {
pub const fn alloc_inodes(&self) -> u64 {
self.alloc_inodes
}

/// Optionally returns the comment.
#[must_use]
pub const fn comment(&self) -> Option<&String> {
self.comment.as_ref()
}
}

/// Returns all filesets of the given file system.
Expand Down Expand Up @@ -99,6 +106,7 @@ struct Index {
fileset_name: Option<usize>,
max_inodes: Option<usize>,
alloc_inodes: Option<usize>,
comment: Option<usize>,
}

fn from_reader<Input: BufRead>(input: Input) -> Result<Vec<Fileset>> {
Expand Down Expand Up @@ -147,11 +155,17 @@ fn from_tokens(tokens: &[&str], index: &Index) -> Result<Fileset> {
.parse()
.with_context(|| "parsing allocInodes value")?;

let comment_index =
index.comment.ok_or_else(|| anyhow!("no comment index"))?;
let comment = tokens[comment_index].replace("%3A", ":");
let comment = Some(comment).filter(|s| !s.is_empty());

Ok(Fileset {
filesystem_name,
fileset_name,
max_inodes,
alloc_inodes,
comment,
})
}

Expand All @@ -162,6 +176,7 @@ fn header_to_index(tokens: &[&str], index: &mut Index) {
"filesetName" => index.fileset_name = Some(i),
"maxInodes" => index.max_inodes = Some(i),
"allocInodes" => index.alloc_inodes = Some(i),
"comment" => index.comment = Some(i),
_ => {}
}
}
Expand Down Expand Up @@ -189,6 +204,7 @@ mod tests {
fileset_name: "public".into(),
max_inodes: 20_971_520,
alloc_inodes: 5_251_072,
comment: None,
})
);

Expand All @@ -199,6 +215,18 @@ mod tests {
fileset_name: "work".into(),
max_inodes: 295_313_408,
alloc_inodes: 260_063_232,
comment: None,
})
);

assert_eq!(
filesets.next(),
Some(Fileset {
filesystem_name: "gpfs1".into(),
fileset_name: "data_foo".into(),
max_inodes: 20_000_768,
alloc_inodes: 1_032_192,
comment: Some("end of project: 2026-11".into()),
})
);

Expand Down

0 comments on commit aa90306

Please sign in to comment.