sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}(hhparenthuba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget(/translations/zh_CN/core-api/watch_queuemodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}(hhhh2ubah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/core-api/watch_queuemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}(hhhhFubah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/core-api/watch_queuemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}(hhhhZubah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/core-api/watch_queuemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}(hhhhnubah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/core-api/watch_queuemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}(hhhhubah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/core-api/watch_queuemodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hGeneral notification mechanismh]hGeneral notification mechanism}(hhhhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/core-api/watch_queue.rsthKubh paragraph)}(hThe general notification mechanism is built on top of the standard pipe driver whereby it effectively splices notification messages from the kernel into pipes opened by userspace. This can be used in conjunction with::h]hThe general notification mechanism is built on top of the standard pipe driver whereby it effectively splices notification messages from the kernel into pipes opened by userspace. This can be used in conjunction with:}(hThe general notification mechanism is built on top of the standard pipe driver whereby it effectively splices notification messages from the kernel into pipes opened by userspace. This can be used in conjunction with:hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh literal_block)}(h* Key/keyring notificationsh]h* Key/keyring notifications}(hhhhubah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhK hhhhubh)}(h,The notifications buffers can be enabled by:h]h,The notifications buffers can be enabled by:}(hhhhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh block_quote)}(hhh]h)}(hA"General setup"/"General notification queue" (CONFIG_WATCH_QUEUE)h]hI“General setup”/”General notification queue” (CONFIG_WATCH_QUEUE)}(hhhhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(h)This document has the following sections:h]h)This document has the following sections:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubhtopic)}(hhh]h bullet_list)}(hhh](h list_item)}(hhh]h)}(hhh]h reference)}(hhh]hOverview}(hOverviewhj#hhhNhNubah}(h]id1ah ]h"]h$]h&]refidoverviewuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]hMessage Structure}(hMessage StructurehjFhhhNhNubah}(h]id2ah ]h"]h$]h&]refidmessage-structureuh1j!hjCubah}(h]h ]h"]h$]h&]uh1hhj@ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]h$Watch List (Notification Source) API}(h$Watch List (Notification Source) APIhjihhhNhNubah}(h]id3ah ]h"]h$]h&]refid"watch-list-notification-source-apiuh1j!hjfubah}(h]h ]h"]h$]h&]uh1hhjcubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]h%Watch Queue (Notification Output) API}(h%Watch Queue (Notification Output) APIhjhhhNhNubah}(h]id4ah ]h"]h$]h&]refid#watch-queue-notification-output-apiuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]hWatch Subscription API}(hWatch Subscription APIhjhhhNhNubah}(h]id5ah ]h"]h$]h&]refidwatch-subscription-apiuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]hNotification Posting API}(hNotification Posting APIhjhhhNhNubah}(h]id6ah ]h"]h$]h&]refidnotification-posting-apiuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]h Watch Sources}(h Watch SourceshjhhhNhNubah}(h]id7ah ]h"]h$]h&]refid watch-sourcesuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]hEvent Filtering}(hEvent FilteringhjhhhNhNubah}(h]id8ah ]h"]h$]h&]refidevent-filteringuh1j!hjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hhh]j")}(hhh]hUserspace Code Example}(hUserspace Code Examplehj;hhhNhNubah}(h]id9ah ]h"]h$]h&]refiduserspace-code-exampleuh1j!hj8ubah}(h]h ]h"]h$]h&]uh1hhj5ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhhhNhNubah}(h]contentsah ](contentslocaleh"]contentsah$]h&]uh1jhhhKhhhhubh)}(hhh](h)}(hj*h]hOverview}(hj*hjkhhhNhNubah}(h]h ]h"]h$]h&]refidj-uh1hhjhhhhhhKubh)}(hXThis facility appears as a pipe that is opened in a special mode. The pipe's internal ring buffer is used to hold messages that are generated by the kernel. These messages are then read out by read(). Splice and similar are disabled on such pipes due to them wanting to, under some circumstances, revert their additions to the ring - which might end up interleaved with notification messages.h]hXThis facility appears as a pipe that is opened in a special mode. The pipe’s internal ring buffer is used to hold messages that are generated by the kernel. These messages are then read out by read(). Splice and similar are disabled on such pipes due to them wanting to, under some circumstances, revert their additions to the ring - which might end up interleaved with notification messages.}(hj{hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhhubh)}(hXThe owner of the pipe has to tell the kernel which sources it would like to watch through that pipe. Only sources that have been connected to a pipe will insert messages into it. Note that a source may be bound to multiple pipes and insert messages into all of them simultaneously.h]hXThe owner of the pipe has to tell the kernel which sources it would like to watch through that pipe. Only sources that have been connected to a pipe will insert messages into it. Note that a source may be bound to multiple pipes and insert messages into all of them simultaneously.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hjhhhubh)}(h|Filters may also be emplaced on a pipe so that certain source types and subevents can be ignored if they're not of interest.h]h~Filters may also be emplaced on a pipe so that certain source types and subevents can be ignored if they’re not of interest.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hjhhhubh)}(hX"A message will be discarded if there isn't a slot available in the ring or if no preallocated message buffer is available. In both of these cases, read() will insert a WATCH_META_LOSS_NOTIFICATION message into the output buffer after the last message currently in the buffer has been read.h]hX$A message will be discarded if there isn’t a slot available in the ring or if no preallocated message buffer is available. In both of these cases, read() will insert a WATCH_META_LOSS_NOTIFICATION message into the output buffer after the last message currently in the buffer has been read.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjhhhubh)}(hX#Note that when producing a notification, the kernel does not wait for the consumers to collect it, but rather just continues on. This means that notifications can be generated whilst spinlocks are held and also protects the kernel from being held up indefinitely by a userspace malfunction.h]hX#Note that when producing a notification, the kernel does not wait for the consumers to collect it, but rather just continues on. This means that notifications can be generated whilst spinlocks are held and also protects the kernel from being held up indefinitely by a userspace malfunction.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjhhhubeh}(h]j3ah ]h"]overviewah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hjMh]hMessage Structure}(hjMhjhhhNhNubah}(h]h ]h"]h$]h&]jxjPuh1hhjhhhhhK4ubh)}(h1Notification messages begin with a short header::h]h0Notification messages begin with a short header:}(h0Notification messages begin with a short header:hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hjhhubh)}(hhstruct watch_notification { __u32 type:24; __u32 subtype:8; __u32 info; };h]hhstruct watch_notification { __u32 type:24; __u32 subtype:8; __u32 info; };}(hhhjubah}(h]h ]h"]h$]h&]hhuh1hhhhK8hjhhubh)}(hX*"type" indicates the source of the notification record and "subtype" indicates the type of record from that source (see the Watch Sources section below). The type may also be "WATCH_TYPE_META". This is a special record type generated internally by the watch queue itself. There are two subtypes:h]hX6“type” indicates the source of the notification record and “subtype” indicates the type of record from that source (see the Watch Sources section below). The type may also be “WATCH_TYPE_META”. This is a special record type generated internally by the watch queue itself. There are two subtypes:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubh)}(hhh]j)}(hhh](j)}(hWATCH_META_REMOVAL_NOTIFICATIONh]h)}(hj h]hWATCH_META_REMOVAL_NOTIFICATION}(hj hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hWATCH_META_LOSS_NOTIFICATION h]h)}(hWATCH_META_LOSS_NOTIFICATIONh]hWATCH_META_LOSS_NOTIFICATION}(hj$hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKDhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]bullet*uh1jhhhKChjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubh)}(hThe first indicates that an object on which a watch was installed was removed or destroyed and the second indicates that some messages have been lost.h]hThe first indicates that an object on which a watch was installed was removed or destroyed and the second indicates that some messages have been lost.}(hjFhjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKFhjhhubh)}(h."info" indicates a bunch of things, including:h]h2“info” indicates a bunch of things, including:}(hjThjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKIhjhhubh)}(hhh]j)}(hhh](j)}(hThe length of the message in bytes, including the header (mask with WATCH_INFO_LENGTH and shift by WATCH_INFO_LENGTH__SHIFT). This indicates the size of the record, which may be between 8 and 127 bytes. h]h)}(hThe length of the message in bytes, including the header (mask with WATCH_INFO_LENGTH and shift by WATCH_INFO_LENGTH__SHIFT). This indicates the size of the record, which may be between 8 and 127 bytes.h]hThe length of the message in bytes, including the header (mask with WATCH_INFO_LENGTH and shift by WATCH_INFO_LENGTH__SHIFT). This indicates the size of the record, which may be between 8 and 127 bytes.}(hjlhjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKKhjfubah}(h]h ]h"]h$]h&]uh1jhjcubj)}(hThe watch ID (mask with WATCH_INFO_ID and shift by WATCH_INFO_ID__SHIFT). This indicates that caller's ID of the watch, which may be between 0 and 255. Multiple watches may share a queue, and this provides a means to distinguish them. h]h)}(hThe watch ID (mask with WATCH_INFO_ID and shift by WATCH_INFO_ID__SHIFT). This indicates that caller's ID of the watch, which may be between 0 and 255. Multiple watches may share a queue, and this provides a means to distinguish them.h]hThe watch ID (mask with WATCH_INFO_ID and shift by WATCH_INFO_ID__SHIFT). This indicates that caller’s ID of the watch, which may be between 0 and 255. Multiple watches may share a queue, and this provides a means to distinguish them.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKOhj~ubah}(h]h ]h"]h$]h&]uh1jhjcubj)}(hA type-specific field (WATCH_INFO_TYPE_INFO). This is set by the notification producer to indicate some meaning specific to the type and subtype. h]h)}(hA type-specific field (WATCH_INFO_TYPE_INFO). This is set by the notification producer to indicate some meaning specific to the type and subtype.h]hA type-specific field (WATCH_INFO_TYPE_INFO). This is set by the notification producer to indicate some meaning specific to the type and subtype.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjubah}(h]h ]h"]h$]h&]uh1jhjcubeh}(h]h ]h"]h$]h&]j<j=uh1jhhhKKhj`ubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubh)}(hCEverything in info apart from the length can be used for filtering.h]hCEverything in info apart from the length can be used for filtering.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhjhhubh)}(hThe header can be followed by supplementary information. The format of this is at the discretion is defined by the type and subtype.h]hThe header can be followed by supplementary information. The format of this is at the discretion is defined by the type and subtype.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKZhjhhubeh}(h]jVah ]h"]message structureah$]h&]uh1hhhhhhhhK4ubh)}(hhh](h)}(hjph]h$Watch List (Notification Source) API}(hjphjhhhNhNubah}(h]h ]h"]h$]h&]jxjsuh1hhjhhhhhK_ubh)}(hXA "watch list" is a list of watchers that are subscribed to a source of notifications. A list may be attached to an object (say a key or a superblock) or may be global (say for device events). From a userspace perspective, a non-global watch list is typically referred to by reference to the object it belongs to (such as using KEYCTL_NOTIFY and giving it a key serial number to watch that specific key).h]hXA “watch list” is a list of watchers that are subscribed to a source of notifications. A list may be attached to an object (say a key or a superblock) or may be global (say for device events). From a userspace perspective, a non-global watch list is typically referred to by reference to the object it belongs to (such as using KEYCTL_NOTIFY and giving it a key serial number to watch that specific key).}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKahjhhubh)}(h=To manage a watch list, the following functions are provided:h]h=To manage a watch list, the following functions are provided:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhjhhubh)}(hhh]j)}(hhh](j)}(hX]:: void init_watch_list(struct watch_list *wlist, void (*release_watch)(struct watch *wlist)); Initialise a watch list. If ``release_watch`` is not NULL, then this indicates a function that should be called when the watch_list object is destroyed to discard any references the watch list holds on the watched object. h](h)}(hpvoid init_watch_list(struct watch_list *wlist, void (*release_watch)(struct watch *wlist));h]hpvoid init_watch_list(struct watch_list *wlist, void (*release_watch)(struct watch *wlist));}(hhhjubah}(h]h ]h"]h$]h&]hhuh1hhhhKlhjubh)}(hInitialise a watch list. If ``release_watch`` is not NULL, then this indicates a function that should be called when the watch_list object is destroyed to discard any references the watch list holds on the watched object.h](hInitialise a watch list. If }(hInitialise a watch list. If hj!hhhNhNubhliteral)}(h``release_watch``h]h release_watch}(hhhj,hhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj!ubh is not NULL, then this indicates a function that should be called when the watch_list object is destroyed to discard any references the watch list holds on the watched object.}(h is not NULL, then this indicates a function that should be called when the watch_list object is destroyed to discard any references the watch list holds on the watched object.hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKohjubeh}(h]h ]h"]h$]h&]uh1jhj ubj)}(h``void remove_watch_list(struct watch_list *wlist);`` This removes all of the watches subscribed to a watch_list and frees them and then destroys the watch_list object itself. h](h)}(h5``void remove_watch_list(struct watch_list *wlist);``h]j+)}(hjQh]h1void remove_watch_list(struct watch_list *wlist);}(hhhjShhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjOubah}(h]h ]h"]h$]h&]uh1hhhhKthjKubh)}(hyThis removes all of the watches subscribed to a watch_list and frees them and then destroys the watch_list object itself.h]hyThis removes all of the watches subscribed to a watch_list and frees them and then destroys the watch_list object itself.}(hjhhjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKvhjKubeh}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]j<j=uh1jhhhKjhj ubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubeh}(h]jyah ]h"]$watch list (notification source) apiah$]h&]uh1hhhhhhhhK_ubh)}(hhh](h)}(hjh]h%Watch Queue (Notification Output) API}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]jxjuh1hhjhhhhhK{ubh)}(hXA "watch queue" is the buffer allocated by an application that notification records will be written into. The workings of this are hidden entirely inside of the pipe device driver, but it is necessary to gain a reference to it to set a watch. These can be managed with:h]hXA “watch queue” is the buffer allocated by an application that notification records will be written into. The workings of this are hidden entirely inside of the pipe device driver, but it is necessary to gain a reference to it to set a watch. These can be managed with:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjhhubh)}(hhh]j)}(hhh](j)}(hX``struct watch_queue *get_watch_queue(int fd);`` Since watch queues are indicated to the kernel by the fd of the pipe that implements the buffer, userspace must hand that fd through a system call. This can be used to look up an opaque pointer to the watch queue from the system call. h](h)}(h0``struct watch_queue *get_watch_queue(int fd);``h]j+)}(hjh]h,struct watch_queue *get_watch_queue(int fd);}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hSince watch queues are indicated to the kernel by the fd of the pipe that implements the buffer, userspace must hand that fd through a system call. This can be used to look up an opaque pointer to the watch queue from the system call.h]hSince watch queues are indicated to the kernel by the fd of the pipe that implements the buffer, userspace must hand that fd through a system call. This can be used to look up an opaque pointer to the watch queue from the system call.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hy``void put_watch_queue(struct watch_queue *wqueue);`` This discards the reference obtained from ``get_watch_queue()``. h](h)}(h5``void put_watch_queue(struct watch_queue *wqueue);``h]j+)}(hjh]h1void put_watch_queue(struct watch_queue *wqueue);}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(h@This discards the reference obtained from ``get_watch_queue()``.h](h*This discards the reference obtained from }(h*This discards the reference obtained from hjhhhNhNubj+)}(h``get_watch_queue()``h]hget_watch_queue()}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh.}(h.hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]j<j=uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubeh}(h]jah ]h"]%watch queue (notification output) apiah$]h&]uh1hhhhhhhhK{ubh)}(hhh](h)}(hjh]hWatch Subscription API}(hjhj9hhhNhNubah}(h]h ]h"]h$]h&]jxjuh1hhj6hhhhhKubh)}(hX(A "watch" is a subscription on a watch list, indicating the watch queue, and thus the buffer, into which notification records should be written. The watch queue object may also carry filtering rules for that object, as set by userspace. Some parts of the watch struct can be set by the driver::h]hX+A “watch” is a subscription on a watch list, indicating the watch queue, and thus the buffer, into which notification records should be written. The watch queue object may also carry filtering rules for that object, as set by userspace. Some parts of the watch struct can be set by the driver:}(hX'A "watch" is a subscription on a watch list, indicating the watch queue, and thus the buffer, into which notification records should be written. The watch queue object may also carry filtering rules for that object, as set by userspace. Some parts of the watch struct can be set by the driver:hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj6hhubh)}(hXEstruct watch { union { u32 info_id; /* ID to be OR'd in to info field */ ... }; void *private; /* Private data for the watched object */ u64 id; /* Internal identifier */ ... };h]hXEstruct watch { union { u32 info_id; /* ID to be OR'd in to info field */ ... }; void *private; /* Private data for the watched object */ u64 id; /* Internal identifier */ ... };}(hhhjUubah}(h]h ]h"]h$]h&]hhuh1hhhhKhj6hhubh)}(hX The ``info_id`` value should be an 8-bit number obtained from userspace and shifted by WATCH_INFO_ID__SHIFT. This is OR'd into the WATCH_INFO_ID field of struct watch_notification::info when and if the notification is written into the associated watch queue buffer.h](hThe }(hThe hjchhhNhNubj+)}(h ``info_id``h]hinfo_id}(hhhjlhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjcubh value should be an 8-bit number obtained from userspace and shifted by WATCH_INFO_ID__SHIFT. This is OR’d into the WATCH_INFO_ID field of struct watch_notification::info when and if the notification is written into the associated watch queue buffer.}(h value should be an 8-bit number obtained from userspace and shifted by WATCH_INFO_ID__SHIFT. This is OR'd into the WATCH_INFO_ID field of struct watch_notification::info when and if the notification is written into the associated watch queue buffer.hjchhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj6hhubh)}(hThe ``private`` field is the driver's data associated with the watch_list and is cleaned up by the ``watch_list::release_watch()`` method.h](hThe }(hThe hjhhhNhNubj+)}(h ``private``h]hprivate}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubhV field is the driver’s data associated with the watch_list and is cleaned up by the }(hT field is the driver's data associated with the watch_list and is cleaned up by the hjhhhNhNubj+)}(h``watch_list::release_watch()``h]hwatch_list::release_watch()}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh method.}(h method.hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj6hhubh)}(hdThe ``id`` field is the source's ID. Notifications that are posted with a different ID are ignored.h](hThe }(hThe hjhhhNhNubj+)}(h``id``h]hid}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh\ field is the source’s ID. Notifications that are posted with a different ID are ignored.}(hZ field is the source's ID. Notifications that are posted with a different ID are ignored.hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj6hhubh)}(h7The following functions are provided to manage watches:h]h7The following functions are provided to manage watches:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj6hhubh)}(hhh]j)}(hhh](j)}(h``void init_watch(struct watch *watch, struct watch_queue *wqueue);`` Initialise a watch object, setting its pointer to the watch queue, using appropriate barriering to avoid lockdep complaints. h](h)}(hE``void init_watch(struct watch *watch, struct watch_queue *wqueue);``h]j+)}(hjh]hAvoid init_watch(struct watch *watch, struct watch_queue *wqueue);}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(h|Initialise a watch object, setting its pointer to the watch queue, using appropriate barriering to avoid lockdep complaints.h]h|Initialise a watch object, setting its pointer to the watch queue, using appropriate barriering to avoid lockdep complaints.}(hj hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(h``int add_watch_to_object(struct watch *watch, struct watch_list *wlist);`` Subscribe a watch to a watch list (notification source). The driver-settable fields in the watch struct must have been set before this is called. h](h)}(hK``int add_watch_to_object(struct watch *watch, struct watch_list *wlist);``h]j+)}(hj%h]hGint add_watch_to_object(struct watch *watch, struct watch_list *wlist);}(hhhj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj#ubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hSubscribe a watch to a watch list (notification source). The driver-settable fields in the watch struct must have been set before this is called.h]hSubscribe a watch to a watch list (notification source). The driver-settable fields in the watch struct must have been set before this is called.}(hj<hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hX:: int remove_watch_from_object(struct watch_list *wlist, struct watch_queue *wqueue, u64 id, false); Remove a watch from a watch list, where the watch must match the specified watch queue (``wqueue``) and object identifier (``id``). A notification (``WATCH_META_REMOVAL_NOTIFICATION``) is sent to the watch queue to indicate that the watch got removed. h](h)}(hint remove_watch_from_object(struct watch_list *wlist, struct watch_queue *wqueue, u64 id, false);h]hint remove_watch_from_object(struct watch_list *wlist, struct watch_queue *wqueue, u64 id, false);}(hhhjRubah}(h]h ]h"]h$]h&]hhuh1hhhhKhjNubh)}(hRemove a watch from a watch list, where the watch must match the specified watch queue (``wqueue``) and object identifier (``id``). A notification (``WATCH_META_REMOVAL_NOTIFICATION``) is sent to the watch queue to indicate that the watch got removed.h](hXRemove a watch from a watch list, where the watch must match the specified watch queue (}(hXRemove a watch from a watch list, where the watch must match the specified watch queue (hj`hhhNhNubj+)}(h ``wqueue``h]hwqueue}(hhhjihhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj`ubh) and object identifier (}(h) and object identifier (hj`hhhNhNubj+)}(h``id``h]hid}(hhhj|hhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj`ubh). A notification (}(h). A notification (hj`hhhNhNubj+)}(h#``WATCH_META_REMOVAL_NOTIFICATION``h]hWATCH_META_REMOVAL_NOTIFICATION}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj`ubhD) is sent to the watch queue to indicate that the watch got removed.}(hD) is sent to the watch queue to indicate that the watch got removed.hj`hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjNubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hX``int remove_watch_from_object(struct watch_list *wlist, NULL, 0, true);`` Remove all the watches from a watch list. It is expected that this will be called preparatory to destruction and that the watch list will be inaccessible to new watches by this point. A notification (``WATCH_META_REMOVAL_NOTIFICATION``) is sent to the watch queue of each subscribed watch to indicate that the watch got removed. h](h)}(hJ``int remove_watch_from_object(struct watch_list *wlist, NULL, 0, true);``h]j+)}(hjh]hFint remove_watch_from_object(struct watch_list *wlist, NULL, 0, true);}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hXJRemove all the watches from a watch list. It is expected that this will be called preparatory to destruction and that the watch list will be inaccessible to new watches by this point. A notification (``WATCH_META_REMOVAL_NOTIFICATION``) is sent to the watch queue of each subscribed watch to indicate that the watch got removed.h](hRemove all the watches from a watch list. It is expected that this will be called preparatory to destruction and that the watch list will be inaccessible to new watches by this point. A notification (}(hRemove all the watches from a watch list. It is expected that this will be called preparatory to destruction and that the watch list will be inaccessible to new watches by this point. A notification (hjhhhNhNubj+)}(h#``WATCH_META_REMOVAL_NOTIFICATION``h]hWATCH_META_REMOVAL_NOTIFICATION}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh]) is sent to the watch queue of each subscribed watch to indicate that the watch got removed.}(h]) is sent to the watch queue of each subscribed watch to indicate that the watch got removed.hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]j<j=uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1hhj6hhhNhNubeh}(h]jah ]h"]watch subscription apiah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hjh]hNotification Posting API}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]jxjuh1hhjhhhhhKubh)}(hwTo post a notification to watch list so that the subscribed watches can see it, the following function should be used::h]hvTo post a notification to watch list so that the subscribed watches can see it, the following function should be used:}(hvTo post a notification to watch list so that the subscribed watches can see it, the following function should be used:hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hvoid post_watch_notification(struct watch_list *wlist, struct watch_notification *n, const struct cred *cred, u64 id);h]hvoid post_watch_notification(struct watch_list *wlist, struct watch_notification *n, const struct cred *cred, u64 id);}(hhhj#ubah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hThe notification should be preformatted and a pointer to the header (``n``) should be passed in. The notification may be larger than this and the size in units of buffer slots is noted in ``n->info & WATCH_INFO_LENGTH``.h](hEThe notification should be preformatted and a pointer to the header (}(hEThe notification should be preformatted and a pointer to the header (hj1hhhNhNubj+)}(h``n``h]hn}(hhhj:hhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj1ubhs) should be passed in. The notification may be larger than this and the size in units of buffer slots is noted in }(hs) should be passed in. The notification may be larger than this and the size in units of buffer slots is noted in hj1hhhNhNubj+)}(h``n->info & WATCH_INFO_LENGTH``h]hn->info & WATCH_INFO_LENGTH}(hhhjMhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj1ubh.}(hjhj1hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe ``cred`` struct indicates the credentials of the source (subject) and is passed to the LSMs, such as SELinux, to allow or suppress the recording of the note in each individual queue according to the credentials of that queue (object).h](hThe }(hThe hjehhhNhNubj+)}(h``cred``h]hcred}(hhhjnhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjeubh struct indicates the credentials of the source (subject) and is passed to the LSMs, such as SELinux, to allow or suppress the recording of the note in each individual queue according to the credentials of that queue (object).}(h struct indicates the credentials of the source (subject) and is passed to the LSMs, such as SELinux, to allow or suppress the recording of the note in each individual queue according to the credentials of that queue (object).hjehhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe ``id`` is the ID of the source object (such as the serial number on a key). Only watches that have the same ID set in them will see this notification.h](hThe }(hThe hjhhhNhNubj+)}(h``id``h]hid}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh is the ID of the source object (such as the serial number on a key). Only watches that have the same ID set in them will see this notification.}(h is the ID of the source object (such as the serial number on a key). Only watches that have the same ID set in them will see this notification.hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jah ]h"]notification posting apiah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hjh]h Watch Sources}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]jxjuh1hhjhhhhhKubh)}(hIAny particular buffer can be fed from multiple sources. Sources include:h]hIAny particular buffer can be fed from multiple sources. Sources include:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hhh]j)}(hhh]j)}(hWATCH_TYPE_KEY_NOTIFY Notifications of this type indicate changes to keys and keyrings, including the changes of keyring contents or the attributes of keys. See Documentation/security/keys/core.rst for more information. h](h)}(hWATCH_TYPE_KEY_NOTIFYh]hWATCH_TYPE_KEY_NOTIFY}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hNotifications of this type indicate changes to keys and keyrings, including the changes of keyring contents or the attributes of keys.h]hNotifications of this type indicate changes to keys and keyrings, including the changes of keyring contents or the attributes of keys.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(h>See Documentation/security/keys/core.rst for more information.h]h>See Documentation/security/keys/core.rst for more information.}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]j<j=uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubeh}(h]jah ]h"] watch sourcesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hjh]hEvent Filtering}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]jxj"uh1hhjhhhhhKubh)}(hrOnce a watch queue has been created, a set of filters can be applied to limit the events that are received using::h]hqOnce a watch queue has been created, a set of filters can be applied to limit the events that are received using:}(hqOnce a watch queue has been created, a set of filters can be applied to limit the events that are received using:hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(histruct watch_notification_filter filter = { ... }; ioctl(fd, IOC_WATCH_QUEUE_SET_FILTER, &filter)h]histruct watch_notification_filter filter = { ... }; ioctl(fd, IOC_WATCH_QUEUE_SET_FILTER, &filter)}(hhhj:ubah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(h.The filter description is a variable of type::h]h-The filter description is a variable of type:}(h-The filter description is a variable of type:hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hstruct watch_notification_filter { __u32 nr_filters; __u32 __reserved; struct watch_notification_type_filter filters[]; };h]hstruct watch_notification_filter { __u32 nr_filters; __u32 __reserved; struct watch_notification_type_filter filters[]; };}(hhhjWubah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hWhere "nr_filters" is the number of filters in filters[] and "__reserved" should be 0. The "filters" array has elements of the following type::h]hWhere “nr_filters” is the number of filters in filters[] and “__reserved” should be 0. The “filters” array has elements of the following type:}(hWhere "nr_filters" is the number of filters in filters[] and "__reserved" should be 0. The "filters" array has elements of the following type:hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hstruct watch_notification_type_filter { __u32 type; __u32 info_filter; __u32 info_mask; __u32 subtype_filter[8]; };h]hstruct watch_notification_type_filter { __u32 type; __u32 info_filter; __u32 info_mask; __u32 subtype_filter[8]; };}(hhhjtubah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hWhere:h]hWhere:}(hjhjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh]j)}(hhh](j)}(h^``type`` is the event type to filter for and should be something like "WATCH_TYPE_KEY_NOTIFY" h]h)}(h]``type`` is the event type to filter for and should be something like "WATCH_TYPE_KEY_NOTIFY"h](j+)}(h``type``h]htype}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubhY is the event type to filter for and should be something like “WATCH_TYPE_KEY_NOTIFY”}(hU is the event type to filter for and should be something like "WATCH_TYPE_KEY_NOTIFY"hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hX2``info_filter`` and ``info_mask`` act as a filter on the info field of the notification record. The notification is only written into the buffer if:: (watch.info & info_mask) == info_filter This could be used, for example, to ignore events that are not exactly on the watched point in a mount tree. h](h)}(h``info_filter`` and ``info_mask`` act as a filter on the info field of the notification record. The notification is only written into the buffer if::h](j+)}(h``info_filter``h]h info_filter}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubh and }(h and hjhhhNhNubj+)}(h ``info_mask``h]h info_mask}(hhhjhhhNhNubah}(h]h ]h"]h$]h&]uh1j*hjubht act as a filter on the info field of the notification record. The notification is only written into the buffer if:}(ht act as a filter on the info field of the notification record. The notification is only written into the buffer if:hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h'(watch.info & info_mask) == info_filterh]h'(watch.info & info_mask) == info_filter}(hhhjubah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubh)}(hlThis could be used, for example, to ignore events that are not exactly on the watched point in a mount tree.h]hlThis could be used, for example, to ignore events that are not exactly on the watched point in a mount tree.}(hj hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(h``subtype_filter`` is a bitmask indicating the subtypes that are of interest. Bit 0 of subtype_filter[0] corresponds to subtype 0, bit 1 to subtype 1, and so on. h]h)}(h``subtype_filter`` is a bitmask indicating the subtypes that are of interest. Bit 0 of subtype_filter[0] corresponds to subtype 0, bit 1 to subtype 1, and so on.h](j+)}(h``subtype_filter``h]hsubtype_filter}(hhhj hhhNhNubah}(h]h ]h"]h$]h&]uh1j*hj ubh is a bitmask indicating the subtypes that are of interest. Bit 0 of subtype_filter[0] corresponds to subtype 0, bit 1 to subtype 1, and so on.}(h is a bitmask indicating the subtypes that are of interest. Bit 0 of subtype_filter[0] corresponds to subtype 0, bit 1 to subtype 1, and so on.hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]j<j=uh1jhhhMhjubah}(h]h ]h"]h$]h&]uh1hhjhhhNhNubh)}(hIf the argument to the ioctl() is NULL, then the filters will be removed and all events from the watched sources will come through.h]hIf the argument to the ioctl() is NULL, then the filters will be removed and all events from the watched sources will come through.}(hjH hjF hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]j(ah ]h"]event filteringah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hjBh]hUserspace Code Example}(hjBhj^ hhhNhNubah}(h]h ]h"]h$]h&]jxjEuh1hhj[ hhhhhM$ubh)}(h7A buffer is created with something like the following::h]h6A buffer is created with something like the following:}(h6A buffer is created with something like the following:hjk hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM&hj[ hhubh)}(hDpipe2(fds, O_TMPFILE); ioctl(fds[1], IOC_WATCH_QUEUE_SET_SIZE, 256);h]hDpipe2(fds, O_TMPFILE); ioctl(fds[1], IOC_WATCH_QUEUE_SET_SIZE, 256);}(hhhjz ubah}(h]h ]h"]h$]h&]hhuh1hhhhM(hj[ hhubh)}(hstatic void consumer(int rfd, struct watch_queue_buffer *buf) { unsigned char buffer[128]; ssize_t buf_len; while (buf_len = read(rfd, buffer, sizeof(buffer)), buf_len > 0 ) { void *p = buffer; void *end = buffer + buf_len; while (p < end) { union { struct watch_notification n; unsigned char buf1[128]; } n; size_t largest, len; largest = end - p; if (largest > 128) largest = 128; memcpy(&n, p, largest); len = (n->info & WATCH_INFO_LENGTH) >> WATCH_INFO_LENGTH__SHIFT; if (len == 0 || len > largest) return; switch (n.n.type) { case WATCH_TYPE_META: got_meta(&n.n); case WATCH_TYPE_KEY_NOTIFY: saw_key_change(&n.n); break; } p += len; } } }h]hX>static void consumer(int rfd, struct watch_queue_buffer *buf) { unsigned char buffer[128]; ssize_t buf_len; while (buf_len = read(rfd, buffer, sizeof(buffer)), buf_len > 0 ) { void *p = buffer; void *end = buffer + buf_len; while (p < end) { union { struct watch_notification n; unsigned char buf1[128]; } n; size_t largest, len; largest = end - p; if (largest > 128) largest = 128; memcpy(&n, p, largest); len = (n->info & WATCH_INFO_LENGTH) >> WATCH_INFO_LENGTH__SHIFT; if (len == 0 || len > largest) return; switch (n.n.type) { case WATCH_TYPE_META: got_meta(&n.n); case WATCH_TYPE_KEY_NOTIFY: saw_key_change(&n.n); break; } p += len; } } }}(hhhj ubah}(h]h ]h"]h$]h&]hhuh1hhhhM1hj[ hhubeh}(h]jKah ]h"]userspace code exampleah$]h&]uh1hhhhhhhhM$ubeh}(h]general-notification-mechanismah ]h"]general notification mechanismah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingUTF-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confapep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacefile_insertion_enabled raw_enabledKline_length_limitM'syntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_link embed_imagesenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j j jej`jj3jjVjjyj3jjjjjjjjX j(j jKu nametypes}(j NjeNjNjNjNj3NjNjNjNjX Nj Nuh}(j hj`jj3jhjVjjyjjjjj6jjjjj(jjKj[ j-j#jPjFjsjijjjjjjjjj"jjEj;u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j K sRparse_messages]transform_messages] transformerN include_log] decorationNhhub.