[dpdk-dev] [PATCH v3 05/10] eal: introduce internal wrappers for file operations

Burakov, Anatoly anatoly.burakov at intel.com
Fri Apr 17 14:24:28 CEST 2020


On 14-Apr-20 8:44 PM, Dmitry Kozlyuk wrote:
> EAL common code uses file locking and truncation. Introduce
> OS-independent wrappers in order to support both Linux/FreeBSD
> and Windows:
> 
> * eal_file_lock: lock or unlock an open file.
> * eal_file_truncate: enforce a given size for an open file.
> 
> Wrappers follow POSIX semantics, but interface is not POSIX,
> so that it can be made more clean, e.g. by not mixing locking
> operation and behaviour on conflict.
> 
> Implementation for Linux and FreeBSD is placed in "unix" subdirectory,
> which is intended for common code between the two. Files should be named
> after the ones from which the code is factored in OS subdirectory.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk at gmail.com>
> ---
>   lib/librte_eal/common/eal_private.h | 45 ++++++++++++++++
>   lib/librte_eal/meson.build          |  4 ++
>   lib/librte_eal/unix/eal.c           | 47 ++++++++++++++++
>   lib/librte_eal/unix/meson.build     |  6 +++
>   lib/librte_eal/windows/eal.c        | 83 +++++++++++++++++++++++++++++
>   5 files changed, 185 insertions(+)
>   create mode 100644 lib/librte_eal/unix/eal.c
>   create mode 100644 lib/librte_eal/unix/meson.build
> 
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index ddcfbe2e4..65d61ff13 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -443,4 +443,49 @@ rte_option_usage(void);
>   uint64_t
>   eal_get_baseaddr(void);
>   
> +/** File locking operation. */
> +enum eal_flock_op {
> +	EAL_FLOCK_SHARED,    /**< Acquire a shared lock. */
> +	EAL_FLOCK_EXCLUSIVE, /**< Acquire an exclusive lock. */
> +	EAL_FLOCK_UNLOCK     /**< Release a previously taken lock. */
> +};
> +
> +/** Behavior on file locking conflict. */
> +enum eal_flock_mode {
> +	EAL_FLOCK_WAIT,  /**< Wait until the file gets unlocked to lock it. */
> +	EAL_FLOCK_RETURN /**< Return immediately if the file is locked. */
> +};

Nitpicking, but why not blocking/unblocking? The terminology seems 
pretty standard.


-- 
Thanks,
Anatoly


More information about the dev mailing list