]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commit
cachefiles: Implement key to filename encoding
authorDavid Howells <dhowells@redhat.com>
Wed, 17 Nov 2021 15:48:06 +0000 (15:48 +0000)
committerDavid Howells <dhowells@redhat.com>
Fri, 26 Nov 2021 21:23:47 +0000 (21:23 +0000)
commita1e5f8750c3c4bdd42608f0a874a97e6af460f25
tree6a7bf5cfc8a1ae6dcd4670e468eed02dd841c01a
parent18180cfc3bce5748d6a21d0cefcfda828d985190
cachefiles: Implement key to filename encoding

Implement a function to encode a binary cookie key as something that can be
used as a filename.  Four options are considered:

 (1) All printable chars with no '/' characters.  Prepend a 'D' to indicate
     the encoding but otherwise use as-is.

 (2) Appears to be an array of __be32.  Encode as 'S' plus a list of
     hex-encoded 32-bit ints separated by commas.  If a number is 0, it is
     rendered as "" instead of "0".

 (3) Appears to be an array of __le32.  Encoded as (2) but with a 'T'
     encoding prefix.

 (4) Encoded as base64 with an 'E' prefix plus a second char indicating how
     much padding is involved.  A non-standard base64 encoding is used
     because '/' cannot be used in the encoded form.

If (1) is not possible, whichever of (2), (3) or (4) produces the shortest
string is selected (hex-encoding a number may be less dense than base64
encoding it).

Note that the prefix characters have to be selected from the set [DEIJST@]
lest cachefilesd remove the files because it recognise the name.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-cachefs@redhat.com
fs/cachefiles/Makefile
fs/cachefiles/internal.h
fs/cachefiles/key.c [new file with mode: 0644]