Skip to content

Commit 3faa9c4

Browse files
committed
Documentation: Add a high-level overview of attributes
Provide an explanation to attribute concepts. Signed-off-by: Petr Tesarik <[email protected]>
1 parent 5b04429 commit 3faa9c4

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dist_noinst_DATA = \
3333
Doxyfile \
3434
NEWS \
3535
README.md \
36+
attributes.md \
3637
objects.md \
3738
threads.md
3839

attributes.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Attributes {#attributes}
2+
==========
3+
4+
All meta-information about a dump file is stored in attributes. All attributes
5+
form a tree-like dictionary, where every attribute is placed according to its
6+
path from the root node. The textual representation of this path, where path
7+
elements are delimited by dots, is called _attribute key_.
8+
9+
Some attributes are present in every [kdump_ctx_t] object, although not
10+
necessarily set. They are called _global attributes_. Other attributes may be
11+
created by the library as needed, e.g. CPU registers. It is not possible to
12+
create a new attribute with an arbitrary path through the public API.
13+
14+
Every attribute has a type and an optional value. The type and value can be
15+
queried with `kdump_get_attr`. If the attribute is unset (i.e. it does not
16+
have a value), this function returns `KDUMP_ERR_NODATA`. Attribute value can
17+
be set (or unset) with `kdump_set_attr`, but the type of an attribute cannot
18+
be changed.
19+
20+
Lifetime
21+
--------
22+
23+
Trivial types do not implement reference counting. The attribute value is
24+
always copied. Following types are trivial:
25+
- `KDUMP_NUMBER`
26+
- `KDUMP_ADDRESS`
27+
- `KDUMP_STRING`
28+
29+
Other attribute types refer to objects, and reference counting is used to make
30+
sure that the object does not unexpectedly disappear if the attribute value is
31+
(directly or indirectly) changed. Following types are reference-counted:
32+
- `KDUMP_BITMAP`
33+
- `KDUMP_BLOB`
34+
35+
For historical reasons, the simple attribute API (`kdump_get_attr`,
36+
`kdump_get_attr` and friends) does not increase the reference count of the
37+
returned data. User of this API must not modify the context object while
38+
making use of the returned attribute value. On the other hand, they don't have
39+
to do anything when they are finished.
40+
41+
When a value is returned by the reference-based API (`kdump_attr_ref_get`),
42+
reference count is increased (or a new dynamic string is allocated). Users of
43+
the attribute reference API should release the underlying resources with a
44+
call to `kdump_attr_discard`.
45+
46+
When a new value is set with `kdump_set_attr`, attributes with a trivial type
47+
make a copy of the new value, and attributes with a reference-counted type
48+
take ownership of the reference from the caller.
49+
50+
Well-known Attributes
51+
---------------------
52+
53+
Some attribute keys are available as macros. The intention is to spot mistakes
54+
earlier: A typo in a macro name is detected at build time, whereas a typo in a
55+
key string is not detected until run time.
56+
57+
Implementation
58+
--------------
59+
60+
Internally, there are two types of attributes:
61+
62+
- global, and
63+
- allocated.
64+
65+
Global attributes are allocated at dictionary initialization time, i.e. they
66+
exist in every dictionary object (albeit possibly unset). They can be looked
67+
up directly using a value from [enum global_keyidx] (identifiers with a `GKI_`
68+
prefix) as an index into the `global_attrs` fixed-size array in
69+
[struct attr_dict]. They can also be looked up through the hash table, like
70+
any other attribute, but that's less efficient, of course.
71+
72+
The values of some global attributes are assumed to be always available and
73+
valid. These values are in fact stored in [struct kdump_shared] and can be
74+
accessed from here with zero overhead by inline helper functions. These
75+
attributes are called _static_ and are used for frequently accessed values,
76+
such as `arch.byte_order` or `file.pagemap`.
77+
78+
It is possible to associate attribute operations with static attributes.
79+
However, the `revalidate` hook is not called when the value is accessed
80+
internally by the library using the `get_` or `sget_` helper functions.
81+
It is usually a bug to set `flags.invalid` for a static attribute.
82+
83+
All non-global attributes are dynamically allocated by `new_attr`, and there
84+
is nothing special about them.
85+
86+
Volatile and Persistent Attributes
87+
----------------------------------
88+
89+
Volatile attributes are cleared when a file format probe returns an error.
90+
Persistent attributes are kept. All attributes set through the public API are
91+
persistent. This implementation detail allows to set attribute values while
92+
probing a file format and remove those attributes automatically if it turns
93+
out to be a different file type.
94+
95+
The difference between volatile and persistent attributes is not visible in
96+
the public API.
97+
98+
[kdump_ctx_t]: @ref kdump_ctx_t
99+
[struct kdump_shared]: @ref kdump_shared
100+
[enum global_keyidx]: @ref global_keyidx
101+
[struct attr_dict]: @ref attr_dict

0 commit comments

Comments
 (0)