25 Jun, 2020

1 commit

  • The encrypt+casefold support needed to be adjusted following refactoring
    of f2fs filename handing upstream. Also, the upstream change to
    f2fs_d_compare() needed to be moved to generic_ci_d_compare(). See
    http://aosp/1341990 and also the other branches like android-5.4-stable.

    Also, a call f2fs_set_bio_crypt_ctx() went missing.

    Fixes: 8912845e4e95 ("Merge 42612e776331 ("Merge tag 'f2fs-for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs") into android-mainline")
    Change-Id: Icd92029bab74e161497a1f03201826a737955725
    Signed-off-by: Eric Biggers

    Eric Biggers
     

10 Jun, 2020

1 commit

  • Pull f2fs updates from Jaegeuk Kim:
    "In this round, we've added some knobs to enhance compression feature
    and harden testing environment. In addition, we've fixed several bugs
    reported from Android devices such as long discarding latency, device
    hanging during quota_sync, etc.

    Enhancements:
    - support lzo-rle algorithm
    - add two ioctls to release and reserve blocks for compression
    - support partial truncation/fiemap on compressed file
    - introduce sysfs entries to attach IO flags explicitly
    - add iostat trace point along with read io stat

    Bug fixes:
    - fix long discard latency
    - flush quota data by f2fs_quota_sync correctly
    - fix to recover parent inode number for power-cut recovery
    - fix lz4/zstd output buffer budget
    - parse checkpoint mount option correctly
    - avoid inifinite loop to wait for flushing node/meta pages
    - manage discard space correctly

    And some refactoring and clean up patches were added"

    * tag 'f2fs-for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (51 commits)
    f2fs: attach IO flags to the missing cases
    f2fs: add node_io_flag for bio flags likewise data_io_flag
    f2fs: remove unused parameter of f2fs_put_rpages_mapping()
    f2fs: handle readonly filesystem in f2fs_ioc_shutdown()
    f2fs: avoid utf8_strncasecmp() with unstable name
    f2fs: don't return vmalloc() memory from f2fs_kmalloc()
    f2fs: fix retry logic in f2fs_write_cache_pages()
    f2fs: fix wrong discard space
    f2fs: compress: don't compress any datas after cp stop
    f2fs: remove unneeded return value of __insert_discard_tree()
    f2fs: fix wrong value of tracepoint parameter
    f2fs: protect new segment allocation in expand_inode_data
    f2fs: code cleanup by removing ifdef macro surrounding
    f2fs: avoid inifinite loop to wait for flushing node pages at cp_error
    f2fs: flush dirty meta pages when flushing them
    f2fs: fix checkpoint=disable:%u%%
    f2fs: compress: fix zstd data corruption
    f2fs: add compressed/gc data read IO stat
    f2fs: fix potential use-after-free issue
    f2fs: compress: don't handle non-compressed data in workqueue
    ...

    Linus Torvalds
     

12 May, 2020

1 commit

  • Rework f2fs's handling of filenames to use a new 'struct f2fs_filename'.
    Similar to 'struct ext4_filename', this stores the usr_fname, disk_name,
    dirhash, crypto_buf, and casefolded name. Some of these names can be
    NULL in some cases. 'struct f2fs_filename' differs from
    'struct fscrypt_name' mainly in that the casefolded name is included.

    For user-initiated directory operations like lookup() and create(),
    initialize the f2fs_filename by translating the corresponding
    fscrypt_name, then computing the dirhash and casefolded name if needed.

    This makes the dirhash and casefolded name be cached for each syscall,
    so we don't have to recompute them repeatedly. (Previously, f2fs
    computed the dirhash once per directory level, and the casefolded name
    once per directory block.) This improves performance.

    This rework also makes it much easier to correctly handle all
    combinations of normal, encrypted, casefolded, and encrypted+casefolded
    directories. (The fourth isn't supported yet but is being worked on.)

    The only other cases where an f2fs_filename gets initialized are for two
    filesystem-internal operations: (1) when converting an inline directory
    to a regular one, we grab the needed disk_name and hash from an existing
    f2fs_dir_entry; and (2) when roll-forward recovering a new dentry, we
    grab the needed disk_name from f2fs_inode::i_name and compute the hash.

    Signed-off-by: Eric Biggers
    Signed-off-by: Jaegeuk Kim

    Eric Biggers
     

08 May, 2020

1 commit

  • sounds very generic and important, like it's the
    header to include if you're doing cryptographic hashing in the kernel.
    But actually it only includes the library implementation of the SHA-1
    compression function (not even the full SHA-1). This should basically
    never be used anymore; SHA-1 is no longer considered secure, and there
    are much better ways to do cryptographic hashing in the kernel.

    Most files that include this header don't actually need it. So in
    preparation for removing it, remove all these unneeded includes of it.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

23 Aug, 2019

1 commit

  • Modeled after commit b886ee3e778e ("ext4: Support case-insensitive file
    name lookups")

    """
    This patch implements the actual support for case-insensitive file name
    lookups in f2fs, based on the feature bit and the encoding stored in the
    superblock.

    A filesystem that has the casefold feature set is able to configure
    directories with the +F (F2FS_CASEFOLD_FL) attribute, enabling lookups
    to succeed in that directory in a case-insensitive fashion, i.e: match
    a directory entry even if the name used by userspace is not a byte per
    byte match with the disk name, but is an equivalent case-insensitive
    version of the Unicode string. This operation is called a
    case-insensitive file name lookup.

    The feature is configured as an inode attribute applied to directories
    and inherited by its children. This attribute can only be enabled on
    empty directories for filesystems that support the encoding feature,
    thus preventing collision of file names that only differ by case.

    * dcache handling:

    For a +F directory, F2Fs only stores the first equivalent name dentry
    used in the dcache. This is done to prevent unintentional duplication of
    dentries in the dcache, while also allowing the VFS code to quickly find
    the right entry in the cache despite which equivalent string was used in
    a previous lookup, without having to resort to ->lookup().

    d_hash() of casefolded directories is implemented as the hash of the
    casefolded string, such that we always have a well-known bucket for all
    the equivalencies of the same string. d_compare() uses the
    utf8_strncasecmp() infrastructure, which handles the comparison of
    equivalent, same case, names as well.

    For now, negative lookups are not inserted in the dcache, since they
    would need to be invalidated anyway, because we can't trust missing file
    dentries. This is bad for performance but requires some leveraging of
    the vfs layer to fix. We can live without that for now, and so does
    everyone else.

    * on-disk data:

    Despite using a specific version of the name as the internal
    representation within the dcache, the name stored and fetched from the
    disk is a byte-per-byte match with what the user requested, making this
    implementation 'name-preserving'. i.e. no actual information is lost
    when writing to storage.

    DX is supported by modifying the hashes used in +F directories to make
    them case/encoding-aware. The new disk hashes are calculated as the
    hash of the full casefolded string, instead of the string directly.
    This allows us to efficiently search for file names in the htree without
    requiring the user to provide an exact name.

    * Dealing with invalid sequences:

    By default, when a invalid UTF-8 sequence is identified, ext4 will treat
    it as an opaque byte sequence, ignoring the encoding and reverting to
    the old behavior for that unique file. This means that case-insensitive
    file name lookup will not work only for that file. An optional bit can
    be set in the superblock telling the filesystem code and userspace tools
    to enforce the encoding. When that optional bit is set, any attempt to
    create a file name using an invalid UTF-8 sequence will fail and return
    an error to userspace.

    * Normalization algorithm:

    The UTF-8 algorithms used to compare strings in f2fs is implemented
    in fs/unicode, and is based on a previous version developed by
    SGI. It implements the Canonical decomposition (NFD) algorithm
    described by the Unicode specification 12.1, or higher, combined with
    the elimination of ignorable code points (NFDi) and full
    case-folding (CF) as documented in fs/unicode/utf8_norm.c.

    NFD seems to be the best normalization method for F2FS because:

    - It has a lower cost than NFC/NFKC (which requires
    decomposing to NFD as an intermediary step)
    - It doesn't eliminate important semantic meaning like
    compatibility decompositions.

    Although:

    - This implementation is not completely linguistic accurate, because
    different languages have conflicting rules, which would require the
    specialization of the filesystem to a given locale, which brings all
    sorts of problems for removable media and for users who use more than
    one language.
    """

    Signed-off-by: Daniel Rosenberg
    Reviewed-by: Chao Yu
    Signed-off-by: Jaegeuk Kim

    Daniel Rosenberg
     

13 Sep, 2018

1 commit


04 May, 2017

1 commit

  • If user has no key under an encrypted dir, fscrypt gives digested dentries.
    Previously, when looking up a dentry, f2fs only checks its hash value with
    first 4 bytes of the digested dentry, which didn't handle hash collisions fully.
    This patch enhances to check entire dentry bytes likewise ext4.

    Eric reported how to reproduce this issue by:

    # seq -f "edir/abcdefghijklmnopqrstuvwxyz012345%.0f" 100000 | xargs touch
    # find edir -type f | xargs stat -c %i | sort | uniq | wc -l
    100000
    # sync
    # echo 3 > /proc/sys/vm/drop_caches
    # keyctl new_session
    # find edir -type f | xargs stat -c %i | sort | uniq | wc -l
    99999

    Cc:
    Reported-by: Eric Biggers
    Signed-off-by: Jaegeuk Kim
    (fixed f2fs_dentry_hash() to work even when the hash is 0)
    Signed-off-by: Eric Biggers
    Signed-off-by: Theodore Ts'o

    Jaegeuk Kim
     

29 May, 2015

1 commit


29 Aug, 2014

1 commit


10 Jul, 2014

1 commit


28 Dec, 2012

2 commits


26 Dec, 2012

1 commit

  • Test Case:
    [NFS Client]
    ls -lR .

    [NFS Server]
    while [ 1 ]
    do
    echo 3 > /proc/sys/vm/drop_caches
    done

    Error on NFS Client: "No such file or directory"

    When cache is dropped at the server, it results in lookup failure at the
    NFS client due to non-connection with the parent. The default path is it
    initiates a lookup by calculating the hash value for the name, even though
    the hash values stored on the disk for "." and ".." is maintained as zero,
    which results in failure from find_in_block due to not matching HASH values.
    Fix up, by using the correct hashing values for these entries.

    Signed-off-by: Namjae Jeon
    Signed-off-by: Amit Sahrawat
    Signed-off-by: Jaegeuk Kim

    Namjae Jeon
     

11 Dec, 2012

3 commits