Skip to content

Commit 87912dd

Browse files
committed
btrfs-progs: docs: update coding style and formatting
Add recent coding style conventions, format key words and phrases for better visibility. [ci skip] Signed-off-by: David Sterba <[email protected]>
1 parent 67fd45e commit 87912dd

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

Documentation/dev/Development-notes.rst

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -230,24 +230,25 @@ already there.*
230230
Patches
231231
^^^^^^^
232232

233-
- for patch subject use "btrfs:" followed by a lowercase
233+
- for patch subject use ``btrfs:`` followed by a lowercase
234234
- read the patch again and fix all typos and grammar
235235
- size units should use short form K/M/G/T or IEC form KiB/MiB/GiB
236236
- don't write references to parameters to subject (like removing @pointer)
237237
- do not end subject with a dot '.'
238238
- parts of btrfs that could have a subject prefix to point to a specific subsystem
239239

240-
- scrub, tests, integrity-checker, tree-checker, discard, locking, sysfs,
241-
raid56, qgroup, compression, send, ioctl
240+
- scrub, tests, integrity-checker, tree-checker, discard, locking, sysfs,
241+
raid56, qgroup, compression, send, ioctl
242242

243243
- additional information
244244

245-
- if there's a stack trace relevant for the patch, add it there (lockdep,
246-
crash, warning)
247-
- steps to reproduce a bug (that will also get turned to a proper fstests
248-
case)
249-
- sample output before/after if it could have impact on userspace
250-
- `pahole <https://linux.die.net/man/1/pahole>`_ output if structure is being reorganized and optimized
245+
- if there's a stack trace relevant for the patch, add it there (lockdep,
246+
crash, warning)
247+
- steps to reproduce a bug (that will also get turned to a proper fstests
248+
case)
249+
- sample output before/after if it could have impact on userspace
250+
- `pahole <https://linux.die.net/man/1/pahole>`__ output if structure is
251+
being reorganized and optimized
251252

252253
Function declarations
253254
^^^^^^^^^^^^^^^^^^^^^
@@ -257,14 +258,14 @@ Function declarations
257258

258259
- but don't move static functions just to get rid of the prototype
259260

260-
- exported functions have btrfs\_ prefix
261+
- exported functions have ``btrfs_`` prefix
261262
- do not use functions with double underscore, there's only a few valid uses of
262263
that, namely when *\__function* is doing the core of the work with looser
263264
checks, no locks or more parameters than *function*
264265
- function type and name are on the same line, if this is too long, the
265266
parameters continue on the next line (indented)
266-
- 'static inline' functions should be small (measured by their resulting binary
267-
size)
267+
- ``static inline`` functions should be small (measured by their resulting binary
268+
size) and not used in .c unless it's justified that inlining makes a difference
268269
- conditional definitions should follow the style below, where the full
269270
function body is in .c
270271

@@ -279,16 +280,18 @@ Function declarations
279280
Headers
280281
^^^^^^^
281282

282-
- leave one newline before #endif in headers
283+
- leave one newline before ``#endif`` in headers
283284
- include headers that add usage of a data structure or API, also remove such
284285
header with last use of the API
286+
- keep the includes in headers self-contained and compilable, add forward
287+
declarations for types if possible
285288

286289
Comments
287290
^^^^^^^^
288291

289292
- function comment goes to the .c file, not the header
290293

291-
- kdoc style is recommended but the exact syntax is not mandated and
294+
- ``kdoc style`` is recommended but the exact syntax is not mandated and
292295
we're using only subset of the formatting
293296
- the first line (mandatory): contains a brief description of what
294297
the function does and should provide a summary information
@@ -321,9 +324,9 @@ Comments
321324
 * Return value semantics if it's not obvious
322325
 */
323326
324-
- comment new enum/define values, brief description or pointers to the code
327+
- comment new ``enum/define`` values, brief description or pointers to the code
325328
that uses them
326-
- comment new data structures, their purpose and context of use
329+
- comment new ``data structures``, their purpose and context of use
327330
- do not put struct member comments on the same line, put it on the line
328331
before and do not trim/abbreviate the text
329332
- comment text that fits on one line can use the */\* text \*/* format, slight
@@ -345,29 +348,37 @@ Locking
345348
- do not use ``spin_is_locked`` but ``lockdep_assert_held``
346349
- do not use ``assert_spin_locked`` without reading it's semantics (it does
347350
not check if the caller hold the lock)
348-
- use ``lockdep_assert_held`` and its friends for lock assertions
351+
- use ``lockdep_assert_held`` and its friends for lock assertions (``lockdep_assert_not_held``,
352+
``lockdep_assert_held_write``)
349353
- add lock assertions to functions called deep in the call chain
354+
- *(to be decided)* do not use ``scoped_guard()`` instead of explicit locking section
355+
- *(to be decided)* using ``guard()`` is possible in justified cases where it improves
356+
readability, i.e. short function (20 lines) with entire body under one lock
350357

351358
Code
352359
^^^^
353360

354-
- default function return value is *int ret*, temporary return values should
355-
be named like *ret2* etc
356-
- structure initializers should use *{ 0 }*
357-
- do not use *short int* type if possible, if it fits to char/u8 use it instead,
361+
- default function return value is ``int ret``, temporary return values should
362+
be named like ``ret2`` etc
363+
- structure initializers should use ``{ 0 }``
364+
- do not use ``short int`` type if possible, if it fits to char/u8 use it instead,
358365
or plain int/u32
359366
- memory barriers need to be always documented
360-
- add *const* to parameters that are not modified
361-
- use bool for indicators and bool status variables (not int)
367+
- add ``const`` to parameters that are not modified
368+
- use ``bool`` for indicators and bool status variables (not int)
362369
- use matching int types (size, signedness), with exceptions
363-
- use ENUM_BIT for enumerated bit values (that don't have assigned fixed numbers)
364-
- add function annotations __cold, __init, __attribute_const__ if applicable
370+
- use ``ENUM_BIT`` for enumerated bit values (that don't have assigned fixed numbers)
371+
- add function annotations ``__cold``, ``__init``, ``__attribute_const__`` if applicable
365372
- use automatic variable cleanup for:
366-
- *struct btrfs_path* with BTRFS_PATH_AUTO_FREE
373+
374+
- *struct btrfs_path* with ``BTRFS_PATH_AUTO_FREE``
375+
- any variable allocated by *kmalloc/kfree* using ``AUTO_KFREE`` or ``AUTO_KVFREE``
376+
- for structures sparsely used do ``__free(...)`` when it does not make sense
377+
to define the cleanup macro
367378
- use of ``unlikely()`` annotation is OK and recommended for the following cases:
368379

369380
- control flow of the function is changed due to error handling and it
370-
leads to *never-happens* errors like EUCLEAN, EIO
381+
leads to *never-happens* errors like ``EUCLEAN``, ``EIO``
371382

372383
Output
373384
^^^^^^
@@ -381,13 +392,13 @@ Output
381392
Expressions, operators
382393
^^^^^^^^^^^^^^^^^^^^^^
383394

384-
- spaces around binary operators, no spaces for unary operators
395+
- spaces around ``binary operators``, no spaces for unary operators
385396
- extra braces around expressions that might be harder to understand wrt
386397
precedence are fine (logical and/or, shifts with other operations)
387398

388399
- *a \* b + c*, *(a << b) + c*, *(a % b) + c*
389400

390-
- 64bit division is not allowed, either avoid it completely, or use bit
401+
- ``64bit division`` is not allowed, either avoid it completely, or use bit
391402
shifts or use div_u64 helpers; do not use *do_div* for division as it's a
392403
macro and has side effects
393404
- do not use chained assignments: no *a = b = c;*
@@ -398,7 +409,7 @@ Variable declarations, parameters
398409
- declaration block in a function should do only simple initializations
399410
(pointers, constants); nothing that would require error handling or has
400411
non-trivial side effects
401-
- use *const* extensively
412+
- use ``const`` extensively
402413
- add temporary variable to store a value if it's used multiple times in the
403414
function, or if reading the value needs to chase a long pointer chain
404415
- do not mix declarations and statements (although kernel uses C standard that
@@ -438,10 +449,6 @@ Please refer to the option documentation for further details.
438449
- **CONFIG_BTRFS_ASSERT**
439450
- **CONFIG_BTRFS_EXPERIMENTAL**
440451
- **CONFIG_BTRFS_FS_RUN_SANITY_TESTS** -- basic tests on module load
441-
- **CONFIG_BTRFS_FS_CHECK_INTEGRITY** -- block integrity checker
442-
enabled by mount options
443-
- **CONFIG_BTRFS_FS_REF_VERIFY** -- additional checks for block
444-
references
445452

446453
- locking
447454

@@ -545,7 +552,7 @@ Storage environment
545552

546553
- at least 4 identically sized partitions/disks/virtual disks, specified using
547554
``$SCRATCH_DEV_POOL``
548-
- some tests may require 8 equally sized``SCRATCH_DEV_POOL`` partitions
555+
- some tests may require 8 equally sized ``SCRATCH_DEV_POOL`` partitions
549556
- some tests need at least 10G of free space, as determined by ``df``, i.e.
550557
the size of the device may need to be larger, 12G should work
551558
- some tests require ``$LOGWRITES_DEV``, yet another separate block device,

0 commit comments

Comments
 (0)