[AIX 운영 체제와 장치 관리 56] AIX 이벤트 인프라(AHAFS) — 가상 파일 시스템, 이벤트 소비자와 생산자, 설정, 모니터 파일 만들기·쓰기, 이벤트 대기, 이벤트 데이터 읽기
https://archive.horanglab.com/posts/aix-osdev-56
핵심 정리
- AIX 이벤트 인프라는 커널이나 커널 확장이 감지하는 상태·값 변화를 가상 파일 시스템의 파일로 나타내, 폴링 없이 기존 파일 시스템 인터페이스로 이벤트를 감시하게 합니다.
- 파일 시스템에는 evProds.list, 이벤트 생산자를 나타내는 .monFactory 디렉터리, 하위 디렉터리, 감시할 이벤트를 나타내는 .mon 파일이 있습니다. 예를 들어
/aha/fs/modFile.monFactory/etc/passwd.mon은/etc/passwd수정을 감시합니다. 메모리 파일 시스템이라 i-node는 32K까지입니다. bos.ahafs를 설치하고mount -v ahafs /aha /aha처럼 마운트하면 커널 확장이 로드되고 모니터 팩토리가 만들어집니다. 한 번에 한 인스턴스만 마운트할 수 있습니다.- 소비자는 모니터 파일을
O_CREAT로 열고WAIT_TYPE, CHANGED=YES나THRESH_HI/THRESH_LO,INFO_LVL,NOTIFY_CNT, CLUSTER,BUF_SIZE를 키=값으로 쓴 뒤 select()나 블로킹 read()로 기다립니다. 감시는 select나 read를 해야 시작됩니다. - 이벤트 데이터는
BEGIN_EVENT_INFO부터END_EVENT_INFO까지의 키워드 쌍(시각, 순번, PID, UID, 현재 값,RC_FROM_EVPROD, 스택 등)이며 read() 한 번에 이벤트 하나만 돌려줍니다. 모니터 대상이 사라지면 모니터 파일이 지워지므로 닫고O_CREAT로 다시 엽니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 6.1 (5.3판에 없는 새 장) |
| 원문 | Operating system and device management — 5.3판 없음, 6.1판 591~603쪽 |
| 관련 명령어와 파일 세트 | bos.ahafs, mount -v ahafs, df |
| 관련 인터페이스 | ahafs_evprods 커널 서비스, open(O_CREAT), write(), select(), read(), poll(), sys/ahafs_evProds.h |
AIX와 AIX 클러스터용 AIX 이벤트 인프라는 미리 정의된 이벤트와 사용자 정의 이벤트를 감시하는 이벤트 감시 프레임워크입니다.
영어 원문
AIX Event Infrastructure for AIX and AIX clusters-AHAFS
AIX Event Infrastructure for AIX and AIX clusters comprise an event monitoring framework for monitoring predefined and user-defined events.
AIX 이벤트 인프라 소개
AIX 이벤트 인프라는 미리 정의된 이벤트와 사용자 정의 이벤트를 감시하는 이벤트 감시 프레임워크입니다.
AIX 이벤트 인프라에서 이벤트는 변화가 일어나는 그때 커널이나 커널 확장이 감지할 수 있는 상태나 값의 모든 변화로 정의됩니다. 감시할 수 있는 이벤트는 가상(pseudo) 파일 시스템의 파일로 나타냅니다. AIX 이벤트 인프라의 장점은 다음과 같습니다.
- 계속 폴링할 필요가 없습니다. 이벤트를 감시하는 사용자는 이벤트가 일어나면 알림을 받습니다.
- 이벤트를 감시하는 사용자에게 이벤트의 자세한 정보(스택 추적, 사용자와 프로세스 정보 등)를 줍니다.
- 기존 파일 시스템 인터페이스를 쓰므로 새 API(응용 프로그래밍 인터페이스)가 필요 없습니다.
- 이벤트가 일어나는 바로 그때 AIX 이벤트 인프라로 제어가 넘어옵니다.
영어 원문
Introduction to the AIX Event Infrastructure
The AIX Event Infrastructure is an event monitoring framework for monitoring predefined and user-defined events.
In the AIX Event Infrastructure, an event is defined as any change of a state or a value that can be detected by the kernel or a kernel extension at the time the change occurs. The events that can be monitored are represented as files in a pseudo file system. Some advantages of the AIX Event infrastructure are:
There is no need for constant polling. Users monitoring the events are notified when those events occur.
Detailed information about an event (such as stack trace and user and process information) is provided to the user monitoring the event.
Existing file system interfaces are used so that there is no need for a new application programming interface (API).
Control is handed to the AIX Event Infrastructure at the exact time the event occurs.
AIX 이벤트 인프라 구성 요소
AIX 이벤트 인프라는 다음 네 구성 요소로 이루어집니다.
- 가상 파일 시스템을 구현하는 커널 확장
- 이벤트를 소비하는 이벤트 소비자
- 이벤트를 만드는 이벤트 생산자
- 커널 확장과 이벤트 생산자 사이 인터페이스 역할을 하는 커널 구성 요소
영어 원문
AIX Event Infrastructure components
The AIX Event Infrastructure is made up of the following four components:
The kernel extension implementing the pseudo file system.
The event consumers that consume the events.
The event producers that produce events.
The kernel component that serve as an interface between the kernel extension and the event producers.
AIX 이벤트 인프라 커널 확장
AIX 이벤트 인프라 커널 확장은 가상 파일 시스템을 구현합니다.
모든 이벤트는 이 파일 시스템의 파일로 나타냅니다. 파일 객체 형식은 넷입니다.
| 형식 | 설명 |
|---|---|
| .list 파일 | 가상 파일 시스템에는 .list 파일이 evProds.list 하나뿐입니다. 읽으면 지금 정의된 모든 이벤트 생산자 이름을 돌려주는 특수 파일입니다. |
| .monFactory 디렉터리 | 모니터 팩토리는 특수한 형식의 디렉터리입니다. 이벤트 생산자를 디렉터리로 나타낸 것입니다. 모니터 팩토리 디렉터리와 그 부모 하위 디렉터리는 사용자를 위해 자동으로 만들어집니다. |
| 하위 디렉터리 | 관리를 쉽게 하고 모니터 파일의 전체 경로 이름을 나타내는 데 씁니다(.mon 파일 참조). |
| .mon 파일 | 모니터 파일은 감시할 수 있는 이벤트를 나타냅니다. 부모 모니터 팩토리부터 모니터 파일까지의 전체 경로 이름에서 .mon 확장자를 뺀 것이 감시하는 이벤트를 완전히 나타냅니다. 예를 들어 /aha/fs/modFile.monFactory/etc/passwd.mon 파일은 /etc/passwd 파일 수정을 감시하는 데 씁니다. 모니터 파일은 모니터 팩토리 아래에만 있을 수 있습니다. |
이 가상 파일 시스템에는 다른 일반 파일을 만들 수 없습니다. AIX 이벤트 인프라 파일 시스템은 메모리 안 파일 시스템이므로 i-node는 최대 32K개까지 있을 수 있습니다. 쓰인 i-node 수는 df 명령 출력에 표시됩니다.
(원문에는 이 뒤에 AIX 이벤트 인프라 파일 시스템의 배치 예 그림이 있습니다.)
참고
evProds.list 파일은 파일 시스템 루트 바로 아래에 있으며, 이 운영 체제 인스턴스에서 정의돼 쓸 수 있는 이벤트 생산자 목록을 담습니다.
LFS 인터페이스를 써서 AIX 이벤트 인프라는 모니터 파일에 쓴 텍스트 입력을 사용자가 이벤트 발생을 어떻게 알림받고 싶은지에 대한 지정으로 바꿉니다. 사용자가 select()나 블로킹 read() 호출을 내 감시 시작을 알리면, AIX 이벤트 인프라는 해당 이벤트 생산자에게 지정한 이벤트 감시를 시작하라고 알립니다.
이벤트 발생이 감지되면 AIX 이벤트 인프라는 감시 기준을 만족한, 기다리는 모든 소비자에게 알립니다.
영어 원문
AIX Event Infrastructure kernel extension
The AIX Event Infrastructure kernel extension implements the pseudo file system.
All events are represented as files in this file system. There are four file object types:
.list files: There is only one .list file in the pseudo file system evProds.list. This is a special file which when read, will return the names of all currently defined event producers.
.monFactory directories: Monitor factories are a special type of directory. These are directory representations of the event producers. Monitor factory directories and their parent subdirectories are automatically created for the user.
subdirectories: Sub directories are used both for ease of management and to represent full path names for monitor files (see .mon files).
.mon files: The monitor files represent the events that can be monitored. The full pathname of a monitor file from its parent monitor factory, minus the .mon extension is the full representation of the
event being monitored. For example, the file /aha/fs/modFile.monFactory/etc/password.mon is used to monitor the modifications to the /etc/passwd file. Monitor files can only exist underneath a monitor factory.
No other regular files can be created in this pseudo file system. Since the AIX Event Infrastructure file system is an in-memory file system, there is a maximum of 32 KB of inodes that may exist. The number of inodes used will be displayed in the df command output.
An example of the layout of an AIX Event Infrastructure file system is shown below:
Note
The evProds.list file exists directly under the root of the file system, and contains the list of event producers that are defined and usable under this operating system instance.
Using the LFS interface, the AIX Event Infrastructure will translate text input written to monitor files into specifications on how the user wants to be notified of event occurrences. Once a user has issued a select() or a blocking read() call to signify the beginning of their monitoring, the AIX Event Infrastructure will notify the corresponding event producer to start monitoring the specified event.
When an event occurrence is detected, the AIX Event Infrastructure will notify all waiting consumers whose monitoring criteria have been met.
이벤트 소비자
이벤트 소비자는 이벤트가 일어나기를 기다리는 사용자 공간 프로세스입니다.
소비자는 언제 어떻게 알림받을지 지정하는 정보를 모니터 파일에 써서 이벤트 감시를 설정합니다. 소비자는 select() 호출이나 블로킹 read() 호출에서 이벤트 알림을 기다릴 수 있습니다.
AIX 이벤트 인프라는 스레드 안전하지 않습니다. 프로세스는 같은 이벤트를 감시하는 데 여러 스레드를 쓰면 안 됩니다.
영어 원문
Event consumers
Event consumers are user space processes that are waiting on events to occur.
Consumers set up event monitoring by writing information to a monitor file specifying how and when they should be notified. Consumers may wait for event notification in a select() call or a blocking read() call.
The AIX Event Infrastructure is not thread safe. Processes should not use multiple threads to monitor the same event.
이벤트 생산자
이벤트 생산자는 이벤트를 감지할 수 있는 커널이나 커널 확장 안의 코드 부분입니다.
감시하는 이벤트가 일어나면 이벤트 생산자는 AIX 이벤트 인프라 커널 확장에 알리고 소비자에게 넘길 이벤트 관련 정보를 보냅니다.
지금 이벤트 생산자에는 크게 두 종류가 있습니다.
- 상태 변화를 감시하는 것
- 값이 사용자가 지정한 임계값을 넘는지 감시하는 것
영어 원문
Event producers
Event producers are sections of code within the kernel or a kernel extension that can detect an event.
When a monitored event occurs, the event producer notifies the AIX Event Infrastructure kernel extension and sends any associated information about the event to pass on to the consumer.
Currently, there are two main classes of event producers:
Those that monitor for a state change
Those that monitor for a value exceeding user-specified thresholds
ahafs_evprods 커널 서비스
ahafs_evprods 커널 서비스는 AIX 이벤트 인프라 커널 확장과 이벤트 생산자 사이 통신을 돕습니다.
AIX 이벤트 인프라 커널 확장과 이벤트 생산자 사이 통신을 돕도록 ahafs_evprods 커널 서비스를 내보냅니다. 커널 안에서는 등록된 이벤트 생산자 목록으로 이벤트 생산자를 찾고, 알맞은 이벤트 생산자와 커널 확장 사이에 정보를 넘깁니다.
영어 원문
ahafs_evprods kernel service
The ahafs_evprods kernel service facilitates communication between the AIX Event Infrastructure kernel extension and event producers.
To facilitate communication between the AIX Event Infrastructure kernel extension and event producers, the ahafs_evprods kernel service is exported. Inside the kernel, a list of registered event producers is used to look up event producers and to pass information between appropriate event producers and the kernel extension.
AIX 이벤트 인프라 설정
AIX 이벤트 인프라를 설정하는 데 필요한 단계입니다.
AIX 이벤트 인프라를 설정하는 데 필요한 단계는 다음뿐입니다.
- bos.ahafs 파일 세트를 설치합니다.
- 원하는 마운트 지점 디렉터리를 만듭니다.
- 다음 명령을 실행합니다.
mount -v ahafs <mount point> <mount point>
예
mkdir /aha
mount -v ahafs /aha /aha
AIX 이벤트 인프라 파일 시스템을 마운트하면 커널 확장이 자동으로 로드되고 모든 모니터 팩토리가 만들어집니다. AIX 이벤트 인프라 파일 시스템은 한 번에 한 인스턴스만 마운트할 수 있습니다. AIX 이벤트 인프라 파일 시스템은 어떤 일반 디렉터리에든 마운트할 수 있지만 /aha를 쓰는 것이 좋습니다.
영어 원문
Setting up the AIX Event Infrastructure
Steps required for setting up the AIX Event Infrastructure.
The only steps necessary to set up the AIX Event Infrastructure are:
Install the bos.ahafs fileset.
Create the directory for the desired mount point.
Run the following command:
mount -v ahafs <mount point> <mount point>
Example
mkdir /aha
mount -v ahafs /aha /aha
Mounting an AIX Event Infrastructure file system will automatically load the kernel extension and create all monitor factories. Only one instance of an AIX Event Infrastructure file system may be mounted at a time. An AIX Event Infrastructure file system may be mounted on any regular directory, but it is suggested that users use /aha.
AIX 이벤트 인프라 동작 개요
소비자 하나가 여러 이벤트를 감시할 수 있고, 여러 소비자가 같은 이벤트를 감시할 수 있습니다. 소비자마다 서로 다른 임계값으로 값 기반 이벤트를 감시할 수 있습니다. 이를 처리하려고 AIX 이벤트 인프라 커널 확장은 소비자마다 다음 정보 목록을 유지합니다.
- 지정한 대기 형식(
WAIT_IN_READ나WAIT_IN_SELECT) - 요청한 정보 수준
- (임계값 이벤트를 감시하면) 감시할 임계값
- 이벤트 발생 정보를 담는 버퍼
이벤트 정보는 프로세스별로 저장되므로 같은 이벤트를 감시하는 서로 다른 프로세스가 이벤트 데이터를 바꾸지 않습니다. 소비자 프로세스가 모니터 파일을 읽으면 자기 이벤트 데이터 사본만 읽습니다.
영어 원문
High-level view of how the AIX Event Infrastructure works
A consumer may monitor multiple events, and multiple consumers may monitor the same event. Each consumer may monitor value-based events with a different threshold value. To handle this, the AIX Event Infrastructure kernel extension keeps a list of each consumer's information including:
Specified wait type (
WAIT_IN_READorWAIT_IN_SELECT)Level of information requested
Threshold (s) for which to monitor (if monitoring a threshold value event)
A buffer used to hold information about event occurrences.
Event information is stored per-process so that different processes monitoring the same event do not alter the event data. When a consumer process reads from a monitor file, it will only read its own copy of the event data.
이벤트 감시의 일반 흐름
이 주제에서는 이벤트를 감시하는 단계를 설명합니다.
- 프로세스가 모니터 파일을 열거나 만들려고 합니다.
- AIX 이벤트 인프라가 모니터 파일 경로 이름을 알맞은 이벤트 생산자에 넘깁니다. 이벤트 생산자는 모니터 파일이 유효한 이벤트를 나타내는지, 프로세스에 이벤트를 감시할 권한이 있는지 확인합니다.
- 프로세스가 파일에 다음을 지정하는 정보를 씁니다.
- 대기 형식(
WAIT_TYPE=WAIT_IN_READ나WAIT_TYPE=WAIT_IN_SELECT). 기본 대기 형식은WAIT_IN_SELECT입니다. - 언제 알림받을지. 상태 변화 이벤트는 CHANGED=YES를 지정해야 합니다. 임계값 이벤트는 관련 이벤트 생산자의 기능에 따라
THRESH_HI=값,THRESH_LO=값, 또는 둘 다를 지정할 수 있습니다. 이 지정에는 기본값이 없으며 CHANGED=YES와THRESH_*=값을 함께 지정할 수 없습니다.
- 대기 형식(
- 그러면 AIX 이벤트 인프라는 이 프로세스에 프로세스별 블록이 아직 없으면 이 정보를 저장할 블록을 할당하고 사용자가 쓴 정보로 채웁니다.
- 프로세스가 모니터 파일에 select()나 블로킹 read()를 냅니다.
- AIX 이벤트 인프라가
ahafs_evprods를 불러 지정한 임계값이 이 이벤트에 유효한지 확인합니다. 예를 들어 utilFs 이벤트 생산자는 100%를 넘는 값을 허용하지 않습니다. 임계값이 유효하지 않으면 select()나 read() 호출은RC_FROM_EVPROD를 돌려주며 모니터 파일을 읽으면 EINVAL이 돌아옵니다. - 임계값 이벤트 생산자에는 임계값(hi나 lo)마다 값 하나만 감시용으로 보냅니다. select()나 블로킹 read() 때 다음 가운데 하나가 참이면 AIX 이벤트 인프라는 이 새 임계값을 이벤트 생산자에 등록합니다.
- 이 이벤트를 감시하는 다른 프로세스가 없으면 이 소비자가 지정한 임계값을 이벤트 생산자에 등록합니다.
- 이 이벤트를 감시하는 다른 프로세스가 있으면, 소비자가 지정한
THRESH_LO가 지금 감시 중인 하한 임계값보다 높거나 소비자가 지정한THRESH_HI가 지금 감시 중인 상한 임계값보다 낮을 때 AIX 이벤트 인프라가ahafs_evprods커널 서비스를 불러 지금 감시 중인 임계값을 갱신합니다.
ahafs_evprods커널 서비스에서 돌아오면 (경우에 따라) 이벤트의 실제 값이 돌아옵니다. 돌아온 실제 값이 이미 어느 한 임계값에 이르렀거나 넘었으면 read()나 select() 호출은 곧바로 돌아오며 이벤트 버퍼에 기록된RC_FROM_EVPROD는 EALREADY입니다. read()나 select() 호출은 0을 돌려줍니다.- 상태 변화 이벤트 생산자에서는 늘
ahafs_evprods함수를 불러 이벤트를 등록합니다. - 등록에 성공하면 AIX 이벤트 인프라가 알림을 설정합니다. select()에서 기다리는 소비자는 selreg()로 알림이 설정됩니다. read() 호출에서 기다리는 소비자는
e_sleep_thread()로 스레드가 잠듭니다. - 이벤트 생산자가 이벤트가 일어났음을 감지하면 이벤트 관련 정보(곧 이벤트를 일으킨 프로세스 정보, 현재 값, 반환 코드 등)와 함께 AIX 이벤트 인프라에 알립니다.
- 이벤트 생산자에서 이 콜백이 오는 동안 AIX 이벤트 인프라는 다음을 합니다.
- 이벤트에 해당하는 ahaNode를 정합니다.
- 기다리는 소비자 목록을 찾아 임계값에 이르렀거나 넘은 소비자를 정하고 selnotify()나
e_wakeup()호출로 알립니다. 상태 변화 이벤트를 기다리는 소비자는 모두 알림받습니다.
- 프로세스가 이벤트 알림을 받으면 모니터 파일을 읽어 이벤트 데이터를 얻습니다. 아래는 이벤트 출력 예입니다. 스택 추적을 받겠다고 지정한 상태 변화 이벤트 생산자의 출력 예는 다음과 같습니다.
BEGIN_EVENT_INFO
TIME_tvsec=1269377315
TIME_tvnsec=955475223
SEQUENCE_NUM=0
PID=2490594
UID=0
UID_LOGIN=0
GID=0
PROG_NAME=cat
RC_FROM_EVPROD=1000
END_EVENT_INFO
임계값 이벤트 예는 다음과 같습니다.
BEGIN_EVENT_INFO
TIME_tvsec=1269378095
TIME_tvnsec=959865951
SEQUENCE_NUM=0
CURRENT_VALUE=2
RC_FROM_EVPROD=1000
END_EVENT_INFO
참고: 프로세스 알림은 비동기이므로 프로세스가 모니터 파일을 읽을 때쯤에는 돌아온 현재 값이 낡았을 수 있습니다. 사용자는 임계값에 처음 이르거나 넘을 때 알림받지만, 감시 중인 값을 바꿀 수 있는 다른 작업은 막히지 않습니다.
영어 원문
Typical flow of monitoring an event
The steps in monitoring an event is described in this topic.
A process attempts to open or create a monitor file.
AIX Event Infrastructure passes the pathname of the monitor file to the appropriate event producer. The event producer verifies that the monitor file represents a valid event and that the process has access to monitor the event.
The process writes information to the file specifying: a. The wait type (
WAIT_TYPE=WAIT_IN_READorWAIT_TYPE=WAIT_IN_SELECT). The default wait type isWAIT_IN_SELECT. b. When to be notified. For state change events, the user must specify CHANGED=YES. For threshold value events, the user may specifyTHRESH_HI=``<value>,THRESH_LO=``<value>, or both, depending on the capabilities of the associated event producer. There is no default for this specification, and CHANGED=YES andTHRESH_*=``<value>may not both be specified.AIX Event Infrastructure will then allocate the per-process block to store this information if one does not already exist for this process and fill it with the information written by the user.
The process issues select() or a blocking read() on the monitor file
AIX Event Infrastructure will call
ahafs_evprodsto check that the thresholds specified are valid for this particular event. For example, the utilFs event producer does not allow values of > 100%. If the threshold is not valid, the select() or read() call will returnRC_FROM_EVPRODand upon a read of the monitor file will be EINVAL returned.For threshold value event producers, only one value is sent to the event producer for each threshold (hi or lo) for monitoring. At select() or blocking read() time, AIX Event Infrastructure will register this new threshold with the event producer if one of the following is true: a. If no other process is monitoring this event, the threshold (s) specified by this consumer are registered with the event producer. b. If there are other processes monitoring this event, then if the
THRESH_LOspecified by the consumer is higher than the currently monitored low threshold OR if theTHRESH_HIspecified by the consumer is lower than the currently monitored high threshold AIX Event Infrastructure calls into theahafs_evprodskernel service to update the currently monitored threshold.Upon return from
ahafs_evprodskernel service, the actual value of the event is returned (in some cases). If the actual value returned has already met or exceeded either threshold, the read() or select() call will return immediately and theRC_FROM_EVPRODlogged in the event buffer will be EALREADY. The read() or select() calls will return 0.For state change event producers, the
ahafs_evprodsfunction is always called to register the event.Upon a successful registration, AIX Event Infrastructure sets up notification. For consumers waiting in select(), the notification is set up through selreg(). For consumers blocking in a read() call, the thread is put to sleep with
e_sleep_thread().Once an event producer detects that an event has occurred, it will notify AIX Event Infrastructure with information regarding the event (i.e. information about the process triggering the event, the current value, the return code, etc.).
During this callback from the event producer, AIX Event Infrastructure will: a. Determine the ahaNode corresponding to the event b. Search the list of waiting consumers to determine whose thresholds have been met or exceeded to notify with the selnotify() or
e_wakeup()call. All consumers waiting on a state change event will be notified.Once the process is notified of the event, it reads from the monitor file to obtain event data. An example of output from an event is below. An example output for a state change event producer who has specified that a stack trace should be taken:
BEGIN_EVENT_INFO
TIME_tvsec=1269377315
TIME_tvnsec=955475223
SEQUENCE_NUM=0
PID=2490594
UID=0
UID_LOGIN=0
GID=0
PROG_NAME=cat
RC_FROM_EVPROD=1000
END_EVENT_INFO
An example for a threshold value event:
BEGIN_EVENT_INFO
TIME_tvsec=1269378095
TIME_tvnsec=959865951
SEQUENCE_NUM=0
CURRENT_VALUE=2
RC_FROM_EVPROD=1000
END_EVENT_INFO
Note: Due to the asynchronous nature of process notification, the current value returned may be stale by the time a process reads the monitor file. Users are notified when the threshold is first met or exceeded, but other operations which may alter the values being monitored will not be blocked.
AIX 이벤트 인프라 사용
AIX 이벤트 인프라 파일 시스템의 모든 디렉터리는 접근 모드가 1777이고 모든 파일은 0666입니다.
지금 AIX 이벤트 인프라 파일 시스템의 모든 디렉터리는 모드가 1777이고 모든 파일은 0666입니다. 이 모드는 바꿀 수 없지만 파일과 디렉터리의 소유권은 바꿀 수 있습니다. 이벤트 감시 접근 제어는 이벤트 생산자 수준에서 합니다. 생성·수정 시각은 유지하지 않으며, 가상 파일 시스템 안 파일 객체에 stat()을 내면 늘 현재 시각을 돌려줍니다. 이 시각을 바꾸려 하면 오류가 돌아옵니다.
영어 원문
Using the AIX Event Infrastructure
All directories in the AIX Event Infrastructure file system have an access mode of 1777 and all files have access mode of 0666.
Currently, all directories in the AIX Event Infrastructure file system have a mode of 1777 and all files have a mode of 0666. These modes cannot be changed, but the ownership of files and directories may be changed. Access control for monitoring events is done at the event producer level. Creation / modification times are not maintained and are always returned as the current time when issuing stat () on a file object within the pseudo file system. Any attempt to modify these times will return an error.
이벤트 감시
모니터 파일 만들기
이벤트를 감시하려면 이벤트에 해당하는 모니터 파일을 만들어야 합니다.
이벤트를 감시하기 전에 이벤트에 해당하는 모니터 파일을 만들어야 합니다. AIX 이벤트 인프라는 O_CREAT 플래그를 쓴 open()을 지원합니다. 예로 파일 시스템 /filesys/clj-fs의 사용률 90%를 감시하는 데 필요한 단계를 따라가 봅니다.
- 필요한 하위 디렉터리도 만들어야 합니다.
mkdir /aha/fs/utilFs.monFactory/filesys
- /aha/fs/utilFs.monFactory/filesys/clj-fs.mon 파일을 엽니다.
모니터 파일을 만들기 전에 AIX 이벤트 인프라 커널 확장은 이벤트 생산자를 불러 요청한 이벤트가 유효한지, 사용자에게 지정한 이벤트를 감시할 권한이 충분한지 판단합니다. 다음은 모니터 파일을 만들거나 열 때 돌아올 수 있는 흔한 오류입니다.
표 71. 반환 코드
| 코드 | 뜻 |
|---|---|
| ENODEV | 지정한 경로에 해당하는 이벤트가 없습니다. 참고: 기존 모니터 파일을 열 때도 그 이벤트가 더는 없으면 ENODEV 오류가 돌아올 수 있습니다. |
| EPERM | 사용자에게 지정한 이벤트를 감시할 권한이 없습니다. |
| ENOTSUP | 지정한 이벤트는 AIX 이벤트 인프라의 감시를 지원하지 않습니다. |
영어 원문
Creating the monitor file
The monitor file corresponding to the event must be created to monitor an event.
Before monitoring an event, the monitor file corresponding to the event must be created. The AIX Event Infrastructure does support open() with the O_CREAT flag. As an example, we will follow the steps required to monitor the file system /filesys/clj-fs for a utilization of 90%.
- The necessary subdirectories must also be created:
mkdir /aha/fs/utilFs.monFactory/filesys
- Open the file /aha/fs/utilFs.monFactory/filesys/clj-fs.mon.
Before a monitor file can be created, the AIX Event Infrastructure kernel extension will call the event producer to determine if the event being requested is valid and to determine if the user has sufficient authority to monitor the specified event. Here are some of the common errors which can be returned
from a monitor file create or open:
Table 71. Return Codes
- ENODEV — There is no event corresponding to the path specified. Note: An ENODEV error may still be returned when trying to open an existing monitor file when the event no longer exists.
- EPERM — User does not have permission to monitor the specified event.
- ENOTSUP — The event specified does not support monitoring by AIX Event Infrastructure.
모니터 파일에 쓰기
소비자 프로세스는 모니터 파일에 써서 이벤트를 언제 어떻게 알림받을지 지정합니다.
원하는 모니터 파일을 만들어 연 뒤 소비자 프로세스는 모니터 파일에 써서 이벤트를 언제 어떻게 알림받을지 지정합니다. 이 데이터는 세미콜론(;)이나 공백으로 구분할 수 있는 키=값 쌍으로 씁니다. 허용되는 키=값 쌍은 다음과 같습니다.
표 72. 허용되는 키=값 쌍
| 키 | 허용 값 | 설명 |
|---|---|---|
| CHANGED | YES | 감시할 이벤트가 AHAFS_THRESHOLD_STATE 형식이고 이벤트 상태가 바뀌면 소비자에게 알려야 함을 지정합니다. |
THRESH_HI |
부호 없는 64비트 정수, 십진수 | 이벤트의 상한 임계값을 지정합니다. 이벤트가 이 임계값에 이르면(같거나 크면) 소비자에게 알립니다. 참고: 64비트 정수이지만 일부 이벤트 생산자는 실제로 감시할 수 있는 값에 제한이 있습니다. 예를 들어 utilFs 이벤트 생산자의 THRESH_HI 허용 값은 1~100입니다. 임계값이 이벤트 생산자에 유효한지는 쓰기 때가 아니라 select()나 블로킹 read() 때 확인합니다. |
THRESH_LO |
부호 없는 64비트 정수, 십진수 | 이벤트의 하한 임계값을 지정합니다. 이벤트가 이 임계값에 이르면(같거나 작으면) 소비자에게 알립니다. 참고: 64비트 정수이지만 일부 이벤트 생산자는 실제로 감시할 수 있는 값에 제한이 있습니다. 예를 들어 utilFs 이벤트 생산자의 THRESH_LO 허용 값은 1~100입니다. 유효성은 select()나 블로킹 read() 때 확인합니다. |
WAIT_TYPE |
WAIT_IN_SELECT(기본값), WAIT_IN_READ |
소비자가 이벤트를 어떻게 기다릴지 지정합니다. select() 호출에서 이벤트를 기다리려면 WAIT_IN_SELECT를, read() 호출에서 기다리려면 WAIT_IN_READ를 지정합니다. |
INFO_LVL |
1, 2(기본값), 3 | 사용자 버퍼에 기록할 이벤트 데이터를 지정합니다. INFO_LVL=1은 이벤트 시각, 순번, 이벤트 생산자 반환 코드, 사용자 정보(주), 프로세스 정보(주), 프로그램 이름(주), (해당하면) 이벤트 현재 값을 기록합니다. INFO_LVL=2는 수준 1의 모든 데이터에 더해 (해당하면) 이벤트 생산자 메시지를 기록합니다. INFO_LVL=3은 수준 2의 모든 데이터에 더해 (해당하면) 이벤트 스택을 기록합니다. (주) 사용자 정보, 프로세스 정보, 프로그램 이름, 스택 추적은 AHAFS_STKTRACE_AVAILABLE 플래그를 지정한 이벤트 생산자에서만 쓸 수 있습니다. 모든 이벤트 생산자가 메시지를 넘기지는 않으므로 어떤 정보가 있는지는 이벤트 생산자 문서를 봅니다. 이벤트 출력 예는 "이벤트 데이터 읽기"를 봅니다. |
NOTIFY_CNT |
-1(기본값), 또는 1~32767 | 프로세스에 알리기 전에 이벤트가 몇 번 일어나야 하는지 지정합니다. -1이면 이벤트가 일어날 때마다 소비자에게 알리고 모든 발생을 사용자 버퍼에 기록합니다. 0이 아닌 양수를 지정하면 이벤트가 그 횟수만큼 일어날 때까지 소비자가 기다립니다. 그 횟수만큼 일어나면 소비자가 다시 select()나 블로킹 read()로 기다릴 때까지 이벤트를 더 기록하지 않습니다. 자세한 내용은 "이벤트 대기"를 봅니다. |
| CLUSTER | YES | 시스템이 클러스터의 일부이고 클러스터가 활성이면, 이 키를 지정해 클러스터의 다른 노드에서 일어난 이 이벤트도 알림받을 수 있습니다. 모든 이벤트 생산자가 클러스터 전체 감시를 지원하지는 않습니다. 기본으로 꺼져 있습니다. 자세한 내용은 "클러스터 이벤트"를 봅니다. |
BUF_SIZE |
1048576까지의 양의 정수 | 이벤트 데이터를 기록할 버퍼 크기를 바이트로 지정합니다. 기본 크기는 2048이며, 소비자가 더 작은 크기를 요청해도 할당되는 가장 작은 크기는 1024바이트입니다. |
모니터 파일에 정보를 쓰는 것은 이어지는 select()나 블로킹 read() 호출을 준비할 뿐입니다. select()나 블로킹 read()를 해야 감시가 시작됩니다.
예를 들어 블로킹 read() 호출에서 파일 시스템 /filesys/clj-fs의 사용률이 처음 90%가 되는 것을 감시하려면 /aha/fs/utilFs.monFactory/filesys/clj-fs.mon 파일에 다음 문자열을 씁니다.
WAIT_TYPE=WAIT_IN_READ THRESH_HI=90 NOTIFY_CNT=1
모니터 파일에 대한 write() 호출이 돌려줄 수 있는 반환 코드는 다음과 같습니다.
표 73. 반환 코드
| 코드 | 뜻 |
|---|---|
| EINVAL | 위 키 가운데 하나에 잘못된 값을 주면 모니터 파일 쓰기는 EINVAL로 실패합니다. 또 지정한 알림 매개변수(CHANGED나 THRESH_HI/LO)가 이벤트 생산자 기능과 맞지 않으면 쓰기는 EINVAL로 실패합니다. 예를 들어 (THRESH_HI/LO만 감시하는) utilFs 이벤트 생산자에 CHANGED=YES를 지정하면 write 호출은 EINVAL을 돌려줍니다. 활성 클러스터 없이 CLUSTER=YES를 지정해도 EINVAL이 됩니다. |
| EBUSY | 프로세스의 다른 스레드가 지금 이벤트를 기다리고 있으면, 다른 스레드가 모니터 파일에 쓸 때 EBUSY를 돌려줍니다. |
| ESTALE | 모니터 파일이 지워졌습니다. 이 이벤트를 감시하려면 파일 설명자를 닫은 뒤 O_CREAT로 다시 열어야 합니다. |
| ENOMEM | 임시 메모리나 이벤트 버퍼용 메모리를 할당할 수 없습니다. |
| ENOSPC | 모니터 파일 하나는 최대 512개 프로세스가 감시할 수 있습니다. 이미 이 파일을 열고 쓴 프로세스가 512개 있으면 쓰기는 ENOSPC로 실패합니다. |
영어 원문
Writing to the monitor file
The consumer process writes to the monitor file to specify how and when it should be notified of events.
Once the monitor file desired is created and opened, the consumer process will write to the monitor file to specify how and when it should be notified of events. This data is written in <key>=<value> pairs which may be separated by a ; or whitespace. The acceptable <key>=<value> pairs are as follows:
Table 72. Acceptable <key>=<value> pairs
| Key | Acceptable Values | Details |
|---|---|---|
| CHANGED | YES | Specifies that the event to be monitored is of AHAFS_THRESHOLD_STATE type and that the consumer should be notified when the state of the event changes. |
THRESH_HI |
Unsigned, 64 bit integer, specified in decimal | This key specifies the high threshold for the event. Once the event has reached this threshold (equal to or greater), the consumer will be notified. Note: While this is a 64 bit integer, some event producers may have limits on what values can actually be monitored. For example, acceptable values for THRESH_HI for the utilFs event producer are between 1 and 100, inclusive. The validity of the threshold for the event producer is not checked at write time, but rather at select() or blocking read() time. |
THRESH_LO |
Unsigned, 64 bit integer, specified in decimal | This key specifies the low threshold for the event. Once the event has reached this threshold (equal to or less than), the consumer will be notified. Note: While this is a 64 bit integer, some event producers may have limits on what values can actually be monitored. For example, acceptable values for THRESH_LO for the utilFs event producer are between 1 and 100, inclusive. The validity of the threshold for the event producer is not checked at write time, but rather at select() or blocking read() time. |
WAIT_TYPE |
WAIT_IN_SELECT (default), WAIT_IN_READ |
Specifies how the consumer will wait for the event. If the consumer wishes to block for the event in a select() call, they should specify WAIT_IN_SELECT. If the consumer wishes to block for the event in a read() call, they should specify WAIT_IN_READ. |
Table 72. Acceptable <key>=<value> pairs (continued)
| Key | Acceptable Values | Details |
|---|---|---|
INFO_LVL |
1, 2 (default), or 3 | Specifies what event data should be logged in the user's buffer: • INFO_LVL=1 will log the timestamp of the event, sequence number, event producer return code, user information*, process information*, program name*, and current value of the event (if applicable). • INFO_LVL=2 will log all data from level 1, plus the message from the event producer, if applicable. • INFO_LVL=3 will log all data from level 2, plus the stack of the event if applicable. Note: The user information, process information, program name and stack trace are only available for event producers which have specified the AHAFS_STKTRACE_AVAILABLE flag. Not all event producers pass messages. See the event producer documentation to determine what info is available. Examples of the event output are shown in the “Reading Event Data” on page 601 section. |
NOTIFY_CNT |
-1 (default), or any value between 1 and 32767, inclusive | The NOTIFY_CNT specifies how many times the event should occur before the process is notified. If the -1 value is specified, the consumer will be notified upon every occurrence of the event and every event occurrence will be logged in the user buffer. If the consumer specifies a positive, non zero value, the consumer will be blocked until the event has occurred the specified number of times. Once the event has occurred the specified number of times, no more events will be logged until the consumer blocks in another select() or blocking read() call. See the “Waiting on events” on page 599 section for more information. |
| CLUSTER | YES | If the system is part of a cluster and the cluster is active, consumers may specify this key to be notified of occurrences of this event on other nodes in the cluster. Not all event producers support cluster-wide monitoring. This feature is off by default. See the “Cluster events” on page 621 section for more information. |
BUF_SIZE |
A positive integer, up to 1048576 | This key specifies the size of the buffer which should be used to record event data, specified in bytes. The default size is 2048, and the smallest size allocated will be 1024 bytes, even if the consumer requests a smaller size. |
Writing information to the monitor file only prepares for a subsequent select() or blocking read() call. Monitoring does not start until a select() or blocking read() is done.
For example, to monitor the file system /filesys/clj-fs for the first occurrence of a utilization of 90% in a blocking read() call, the following string is written to the /aha/fs/utilFs.monFactory/filesys/clj-fs.mon file:
WAIT_TYPE=WAIT_IN_READ THRESH_HI=90 NOTIFY_CNT=1
Possible return codes from a write() call to a monitor file:
Table 73. Return Codes
- EINVAL — If an invalid value is given for any of the above keys, the write to the monitor file will fail with EINVAL. In addition, if the notify parameters (CHANGED or
THRESH_HI/LO) specified do not match with the capabilities of the event producer, the write will fail with EINVAL. For example, if the consumer specifies CHANGED=YES for the utilFs event producer (which only monitors forTHRESH_HI/LO), the write call will return EINVAL. Specifying CLUSTER=YES without an active cluster will also result in EINVAL. - EBUSY — If there is another thread in the process which is currently waiting on the event, a write to the monitor file by any other thread will return EBUSY.
- ESTALE — The monitor file has been deleted. In order to monitor this event, the file descriptor will need to be closed, then reopened with
O_CREAT - ENOMEM — Unable to allocate temporary memory or memory for the event buffer.
- ENOSPC — A maximum of 512 processes may monitor a monitor file. If there are already 512 processes with this file open who have written to it, the write will fail with ENOSPC.
이벤트 대기
감시 지정을 모니터 파일에 씁니다.
감시 지정을 모니터 파일에 성공적으로 쓴 뒤 소비자 프로세스는 select()나 read()로 이벤트 발생을 기다립니다. 소비자는 select()나 read()에서 기다리기 시작한 뒤 일어난 이벤트만 알림받습니다. 프로세스가 select()나 블로킹 read()에서 돌아오는 경우는 세 가지입니다.
이벤트가 지정한 횟수만큼 일어났습니다.
- 오류가 아닌 경우입니다. 소비자는 이벤트 데이터를 읽어 이벤트를 어떻게 처리할지 정해야 합니다.
AIX 이벤트 인프라 커널 확장 안에서 이벤트를 설정하다 문제가 생겼습니다. 이벤트 생산자에 감시할 이벤트를 등록하기 전에 오류가 날 수 있습니다.
- read() — 다른 스레드가 read에서 기다리고 있으면 read는 EBUSY로 실패합니다. 이 read 전에 write를 하지 않았으면 read는 0바이트를 읽고 0을 돌려줍니다.
- select() — select 시스템 호출 구현 때문에 select()가 오류를 돌려주려면 기반 파일 시스템 작업이 EBADF를 돌려줘야 합니다. 그래서 다른 스레드가 select를 시도하고 있거나, 모니터 파일이 지워졌거나, 감시 지정을 쓰는 write를 하지 않았거나, IOS 하위 시스템에 등록하다 오류가 나면 select()는 EBADF를 돌려줍니다.
이 경우 읽을 이벤트 데이터는 없습니다.
이벤트 생산자에 이벤트를 설정하다 문제가 생겼습니다. 이벤트 생산자에 이벤트를 등록하려 한 경우 소비자가 읽을 항목이 버퍼에 기록됩니다. 어떤 오류가 났는지 알려면 이벤트 데이터에 돌아온
RC_FROM_EVPROD를 이벤트 생산자 문서에서 찾아봐야 합니다. 이 경우 이벤트 출력에는 지정한INFO_LVL과 상관없이 시각, 순번, 이벤트 생산자 반환 코드만 들어 있습니다. 예는 이벤트 데이터 읽기를 봅니다. 이 경우 select()는 EBADF를 돌려주지만 read()는 기반uio_move작업의 반환 코드를 돌려줍니다.
소비자 프로세스가 NOTIFY_CNT를 1보다 크게 지정했으면 요청한 수만큼 이벤트가 일어날 때까지 각 이벤트 발생 정보가 소비자 버퍼에 기록됩니다. 소비자 프로세스는 이벤트가 요청한 횟수만큼 일어났거나 사용 불가 이벤트가 일어났을 때만 깨어납니다. 깨어난 소비자 프로세스는 모니터 파일에 select()나 블로킹 read() 호출을 다시 낼 때까지 이벤트를 감시하지 않습니다.
소비자가 NOTIFY_CNT를 -1로 지정했으면 소비자 프로세스는 이벤트가 일어날 때마다 깨어나며, 첫 성공 select()나 블로킹 read() 뒤에 일어난 모든 이벤트가 소비자 버퍼에 기록됩니다.
버퍼에 읽지 않은 이벤트 데이터가 있으면 select()와 read() 호출은 기다리지 않습니다.
영어 원문
Waiting on events
Monitoring specifications are written to the monitor file.
Once monitoring specifications are successfully written to the monitor file, the consumer process will block for an event occurrence using select() or read(). Consumers are only notified of events that occur once they block in select() or read(). There are three ways that the process can return from select() or a blocking read():
- The event has occurred the specified number of times.
- Non-error case. Consumer should read event data to determine how to handle the event.
- There was a problem when setting up the event inside the AIX Event Infrastructure kernel extension. Errors may occur before the event is registered for monitoring with the event producer:
read() – If there is another thread waiting in read, the read will fail with EBUSY – If there was no write done before this read, the read will just return 0, with 0 bytes read.
select()
Note
Due to the implementation of the select system call, in order for select() to return an error, the underlying file system operations must return EBADF. As a result, if any of the following conditions are met, select() will return EBADF. – Another thread is attempting a select – The monitor file has been deleted – There was no write done specifying monitoring specifications – There was an error when registering with the IOS subsystem
In these cases, there will be no event data to read.
- There was a problem setting up the event with the event producer. If an attempt is made to register the event with the event producer, an entry will be logged into the buffer for the consumer to read. To determine what error occurred, the
RC_FROM_EVPRODreturned in the event data should be referenced in the event producer's documentation. Note that the event output for this case will only contain the timestamp, sequence number and return code from the event producer, regardless of whatINFO_LVLhas been specified. See Reading Event Data for an example. In this case, select() will return EBADF, but read() will return the return code from the underlyinguio_moveoperation.
If the consumer process has specified a NOTIFY_CNT greater than 1, information about each event occurrence will be logged in the consumer's buffer until the number of events request have occurred. The consumer process will only be woken up if the event has occurred the requested number of times, or an unavailable event has occurred. Once the consumer process is woken up, it will no longer be monitoring the event until it re-issues a select() or blocking read() call for the monitor file.
If a consumer has specified a NOTIFY_CNT of -1, the consumer process will be woken up after each occurrence of the event, and any event which occurs after the initial successful select() or blocking read() will be logged in the consumer buffer.
The select() and read() calls will not block if there is unread event data in the buffer.
사용 불가 이벤트 발생
일부 이벤트 생산자에서는 감시하는 이벤트를 무효로 만드는 이벤트 발생이 있을 수 있습니다.
예는 다음과 같습니다.
- processMon과 pidProcessMon에서 프로세스가 죽음
- modDir과 modFile에서 감시하는 파일이 든 파일 시스템의 마운트 해제
- utilFs가 감시하는 파일 시스템의 마운트 해제
- modDir이나 modFile이 감시하는 파일의 제거나 이름 바꾸기
- 지금 이벤트 감시에 쓰고 있는 이벤트 생산자의 제거(이 경우
RC_FROM_EVPROD는 ENODEV)
사용 불가 이벤트 발생이 일어나면 소비자는 이벤트가 다시 유효해질 때까지 그 이벤트를 계속 감시할 수 없습니다. 이벤트가 다시 유효해지는 예는 다음과 같습니다.
- 감시하던 파일 시스템을 다시 마운트함
- 지워진 감시 파일을 다시 만듦
- 감시하던 프로세스를 다시 만듦
로컬 사용 불가 이벤트가 일어나면 AIX 이벤트 인프라 커널 확장은 영향받는 모니터 파일을 지웁니다. 모니터 파일이 지워지면 아직 파일을 열고 있는 소비자는 이벤트 데이터를 읽을 수 있지만, 그 모니터 파일에 쓰거나 이벤트 발생을 기다릴 수는 없습니다. 소비자는 사용 불가 이벤트 발생을 만나면 알맞은 조치(아마 이벤트를 다시 유효하게 만드는 조치)를 하고, 모니터 파일의 파일 설명자를 닫은 뒤 O_CREAT 플래그로 모니터 파일을 다시 열어야 합니다.
소비자가 NOTIFY_CNT를 1보다 크게 지정했으면, 로컬 사용 불가 이벤트 발생은 요청한 수만큼 이벤트가 일어나기 전에 select()와 read()의 대기를 풉니다. 예를 들어 소비자가 NOTIFY_CNT=3으로 /foo 파일을 감시하고 있으면, /foo에 대한 첫 이벤트 발생이더라도 /foo가 지워지면 소비자는 select()나 read()에서 돌아옵니다.
영어 원문
Unavailable Event Occurrences
For some event producers, there may be event occurrences that cause the monitored event to become invalid.
Some examples are:
The death of a process for processMon and pidProcessMon .
The unmounting of a file system containing monitored files for modDir and modFile .
The unmounting of a file system which is being monitored by utilFs .
The removal or renaming of a file which is being monitored by modDir or modFile
The removal of an event producer which is currently being used to monitor events (The
RC_FROM_EVPRODwill be ENODEV in this case).
Once an unavailable event occurrence has been triggered, the consumers may not continue to monitor for that event until it becomes valid again. Examples of events becoming valid again:
The remounting of a monitored file system.
The recreation of a monitored file that was deleted.
The recreation of a process that was being monitored.
When a local unavailable event is triggered, the AIX Event Infrastructure kernel extension will remove the monitor file(s) affected. When a monitor file is deleted, consumers who still have the file open will be able to read their event data, but will not be able to write or block waiting for an event occurrence on that monitor file. When an unavailable event occurrence is encountered by the consumer, they should take the appropriate action (which will presumably cause the event to become valid again), close the file descriptor for the monitor file, and re-open the monitor file with the O_CREAT flag.
Local unavailable event occurrences will also cause select() and read() to unblock before the requested number of events occurrences have been triggered if the consumer has specified a NOTIFY_CNT > 1. For example, if a consumer is monitoring file /foo with a NOTIFY_CNT=3, the consumer will return from select() or read() if /foo is removed even if it is the first occurrence of an event with /foo.
폴링에 AIX 이벤트 인프라 사용
AIX 이벤트 인프라는 이벤트 생산자가 감시할 수 있는 이벤트의 현재 값을 늘 유지하도록 요구하지 않습니다.
아무도 이벤트 발생을 감시하지 않으면 이벤트 생산자가 이 값을 유지하는 부담이 없으므로 성능이 좋아집니다.
그러나 동기 폴링을 쓸 때 문제가 생깁니다. 모든 시점에 이벤트의 현재 값을 늘 얻을 수 있는 것은 아니므로 poll()이나 동기 select() 호출은 다음과 같이 처리합니다.
- 프로세스가 모니터 파일에 처음 select()나 poll()을 내면 AIX 이벤트 인프라 커널 확장은 이벤트 생산자에 그 이벤트를 감시용으로 등록합니다.
- 현재 값을 유지하는 임계값 이벤트 생산자는 이벤트를 등록할 때 AIX 이벤트 인프라 커널 확장에 현재 값을 돌려줍니다. 이때 이 값을 소비자 임계값과 비교합니다. 소비자 임계값을 넘었으면 select()나 poll()은 이벤트가 일어났다고 알리고
RC_FROM_EVPROD는 EALREADY입니다.
- 현재 값을 유지하는 임계값 이벤트 생산자는 이벤트를 등록할 때 AIX 이벤트 인프라 커널 확장에 현재 값을 돌려줍니다. 이때 이 값을 소비자 임계값과 비교합니다. 소비자 임계값을 넘었으면 select()나 poll()은 이벤트가 일어났다고 알리고
- POLLSYNC 플래그는 무시됩니다. 이벤트는 지정한 횟수만큼 일어나거나 사용자가 파일을 닫을 때까지 이벤트 생산자에 등록된 채로 남습니다.
- 이어지는 poll() 호출은 다음과 같이 동작합니다.
- 이벤트가 아직 일어나지 않았으면 반환 이벤트 없이 돌아옵니다.
- 마지막 poll() 호출 뒤 이벤트가 지정한 횟수만큼 일어났으면 반환 이벤트를 설정해 이벤트가 일어났음을 알립니다.
영어 원문
Using AIX Event Infrastructure for polling
AIX Event Infrastructure does not require that event producers always maintain the current value of events which may be monitored.
This is to allow for greater performance since event producers do not have the overhead of maintaining this value if no one is monitoring for occurrences of the event.
This creates a problem when using synchronous polling. Since it is not always possible to obtain the current value of an event at every point in time, poll() or synchronous select() calls are handled in the following way:
When a process issues select() or poll() on a monitor file for the first time, the AIX Event Infrastructure kernel extension will register that event for monitoring with the event producer. – For threshold value event producers who do maintain the current value, the current value will be returned to the AIX Event Infrastructure kernel extension upon event registration. This value will be checked against the consumer threshold value at this time. If the consumer's threshold has been exceeded, the select() or poll() will indicate that the event has occurred and will have an
RC_FROM_EVPRODof EALREADY.POLLSYNC flags are ignored. An event remains registered with the event producer until the event occurs the specified number of times, or until the user closes the file.
Subsequent poll() calls will have the following behavior: – If the event has not yet occurred, the call will return with no return events – If the event has occurred the specified number of times since the last poll() call, return events will be set to indicate that the event has occurred.
이벤트 데이터 읽기
AIX 이벤트 인프라의 이벤트 데이터는 키워드·값 쌍으로 이루어집니다.
이벤트 데이터는 한 번만 읽을 수 있으며, read() 호출 한 번에 이벤트 발생 하나 분량보다 많은 데이터는 돌아오지 않습니다. 예를 들어 소비자가 모니터 파일을 읽기 전에 이벤트가 두 번 일어났고 이벤트마다 데이터가 256바이트라고 합시다. 소비자가 4096바이트로 read()를 부르면 첫 이벤트의 256바이트만 돌아옵니다. 둘째 이벤트 데이터를 얻으려면 read()를 한 번 더 불러야 합니다. 주어진 오프셋은 무시되며 마지막으로 읽지 않은 바이트부터 읽습니다.
이벤트 데이터는 최대 4096바이트이지만 대부분의 이벤트는 훨씬 작습니다(512바이트 미만). 이벤트를 읽을 때는 이벤트 일부만 읽지 않도록 충분히 큰 버퍼를 쓰는 것이 좋습니다.
AHAFS의 이벤트 데이터는 키워드 = 값 쌍으로 이루어지며, 값 없는 특수 키워드인 BUF_WRAP, EVENT_OVERFLOW, BEGIN_EVENT_INFO, END_EVENT_INFO, BEGIN_EVPROD_INFO, END_EVPROD_INFO, STACK_TRACE는 예외입니다. 이벤트 데이터에서 볼 수 있는 키워드는 다음과 같습니다.
표 74. 키워드
| 키 | 값 | 설명 |
|---|---|---|
BUF_WRAP |
없음 | 소비자 버퍼는 원형 버퍼처럼 다뤄집니다. 읽지 않은 데이터가 최신 이벤트 데이터로 덮어쓰이면, 소비자가 앞 항목을 일부 읽었더라도 이 키워드가 read() 호출이 돌려주는 다음 문자열이 됩니다. 이어지는 read() 호출은 다음 이벤트 전체를 돌려줍니다. |
EVENT_OVERFLOW |
없음 | 이벤트 데이터가 너무 커 소비자의 이벤트 데이터 버퍼에 들어가지 않으면 첫 read()가 이 키워드를 돌려줍니다. 이어지는 read()는 버퍼에 들어간 이벤트 데이터를 돌려줍니다. 참고: EVENT_OVERFLOW가 나오면 끝 문자열 END_EVENT_INFO는 없습니다. |
BEGIN_EVENT_INFO |
없음 | 이벤트 발생 데이터의 시작을 나타냅니다. |
END_EVENT_INFO |
없음 | 이 이벤트 발생 데이터의 끝을 나타냅니다. |
TIME_tvsec, TIME_tvnsec |
정수 | 이벤트 발생 시각을 Epoch 이후 초와 나노초로 기록합니다. |
SEQUENCE_NUM |
정수 | 첫 성공 select()나 블로킹 read() 이후 이벤트가 일어난 횟수를 기록합니다. select()나 블로킹 read() 호출이 실패하거나, 소비자가 (감시 지정을 덮어쓰거나 지정한 NOTIFY_CNT만큼 이벤트가 일어나) 감시를 그만두면 0으로 재설정됩니다. |
| PID | 정수 | 이벤트 발생을 일으킨 프로세스의 프로세스 ID입니다. AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서만 쓸 수 있습니다. |
| UID | 정수 | 이벤트 발생을 일으킨 사용자의 유효 사용자 ID입니다. AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서만 쓸 수 있습니다. |
UID_LOGIN |
정수 | 이벤트 발생을 일으킨 사용자의 로그인 사용자 ID입니다. AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서만 쓸 수 있습니다. |
| GID | 정수 | 이벤트 발생을 일으킨 사용자의 유효 그룹 ID입니다. AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서만 쓸 수 있습니다. |
PROG_NAME |
문자열 | 이벤트 발생을 일으킨 프로세스 이름입니다. AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서만 쓸 수 있습니다. |
CURRENT_VALUE |
부호 없는 64비트 정수, 십진수 | AHAFS_THRESHOLD_VALUE 이벤트 생산자에만 해당하며, 이벤트 발생을 감지한 때의 이벤트 현재 값을 돌려줍니다. 프로세스가 알림받은 때와 이벤트 데이터를 읽는 때 사이의 지연 때문에 이벤트의 실제 현재 값은 바뀌었을 수 있습니다. |
RC_FROM_EVPROD |
32비트 정수, 십진수 | 이벤트를 설정하려다 오류가 났거나 이벤트가 일어난 결과로 이벤트 생산자가 주는 반환 코드입니다. 일반적으로 256보다 작은 반환 코드는 이벤트 생산자에 이벤트를 등록하려다 오류가 났다는 뜻입니다. 일부 이벤트 생산자는 이벤트 발생 정보를 더 주려고 256보다 큰 코드를 돌려줍니다. 이 반환 코드는 sys/ahafs_evProds.h에 문서화돼 있습니다. |
BEGIN_EVPROD_INFO, END_EVPROD_INFO |
문자열 | 이벤트 생산자가 돌려준 문자열의 시작과 끝을 표시합니다. BEGIN_EVPROD_INFO 뒤와 END_EVPROD_INFO 앞에는 늘 줄 바꿈이 있습니다. CLUSTER=YES를 지정한 소비자에게는 여기에 노드 정보가 나옵니다. |
STACK_TRACE |
문자열 | AHAFS_STKTRACE_AVAILABLE 기능을 지정했지만 AHAFS_CALLBACK_INTRCNTX 기능은 지정하지 않은 이벤트 생산자에서 INFO_LVL=3을 지정한 소비자에게 이벤트 발생의 스택 추적을 줍니다. 키워드 STACK_TRACE는 문자열 END_EVENT_INFO까지 남은 이벤트 데이터가 이벤트 발생의 스택임을 나타냅니다. |
NUM_EVDROPS_INTRCNTX |
정수 | 보고서의 TIME0_tvsec과 TIME0_tvnsec 키워드가 지정한 시각 이후 버려진 인터럽트 컨텍스트 이벤트 발생 수입니다. 이벤트 발생 빈도가 높을 때만 버려집니다. |
TIME0_tvsec, TIME0_tvnsec |
정수 | 첫 이벤트 발생이 버려진 시각을 Epoch 이후 초와 나노초로 기록합니다. NUM_EVDROPS_INTRCNTX 키워드와 함께 보고됩니다. |
중복 이벤트 통합
소비자가 데이터를 읽기 전에 같은 이벤트가 여러 번 일어나면 중복 항목은 한 항목으로 통합됩니다. 이 통합은 BUF_WRAP 키워드 없이 순번이 이어지지 않는 것으로 알 수 있습니다. 시각과 순번은 가장 최근 이벤트 발생을 반영합니다.
영어 원문
Reading Event Data
Event data in AIX Event Infrastructure consists of keyword-value pairs.
Event data may only be read once and no more than one event occurrence worth of data will be returned in a single read() call. For example, say that two events have occurred before the consumer reads from the monitor file and each event has 256 bytes worth of data. If the consumer calls read() for 4096 bytes, only the 256 bytes of the first event will be returned to the user. A second read() call will need to be performed to obtain the data from the second event. Any offset given will be ignored and data will be read starting from the last unread byte.
Event data will be at the most 4096 bytes, although most events will be much smaller ( < 512 bytes). It is recommended that when reading events, a large enough buffer should be used so as to avoid only reading part of an event.
Event data in AHAFS consists of keyword = value pairs, with the exception of BUF_WRAP, EVENT_OVERFLOW, BEGIN_EVENT_INFO, END_EVENT_INFO, BEGIN_EVPROD_INFO, END_EVPROD_INFO and STACK_TRACE which are special keywords without any values. Here are the keywords you may see in event data:
Table 74. Keywords
| Key | Value | Details |
|---|---|---|
BUF_WRAP |
None | The consumer buffer is handled like a circular buffer. If any unread data is overwritten by the latest event data, this keyword will be the next string returned by the read() call even if the consumer has partially read the previous entry. The subsequent call to read() will return the next whole event. |
Table 74. Keywords (continued)
| Key | Value | Details |
|---|---|---|
EVENT_OVERFLOW |
None | If the event data is too large to fit inside the consumer's event data buffer, this keyword will be returned from the first read(). A subsequent read() will return what event data was able to fit inside the buffer. Note: If EVENT_OVERFLOW is encountered, the end string END_EVENT_INFO will not be present. |
BEGIN_EVENT_INFO |
None | This keyword signifies the beginning of the data for an event occurrence. |
END_EVENT_INFO |
None | This keyword signifies the end of the data for this specific event occurrence. |
TIME_tvsec TIME_tvnsec |
Integer | These two fields record the timestamp of the event occurrence as seconds and nano-seconds since the Epoch. |
SEQUENCE_NUM |
Integer | This field records the number of times the event has occurred since the first successful select() or blocking read(). This number is reset to 0 if the select() or blocking read() call fails, or if the consumer ceases to monitor the event (through overwriting of the event monitoring specifications, or through reaching an event occurrence count equal to the NOTIFY_CNT specified). |
| PID | Integer | Process ID of the process which triggered the event occurrence. Only available with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability. |
| UID | Integer | Effective user ID of the user who triggered the event occurrence. Only available with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability. |
UID_LOGIN |
Integer | Login user ID of the user who triggered the event occurrence. Only available with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability. |
| GID | Integer | Effective group ID of the user who triggered the event occurrence. Only available with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability. |
Table 74. Keywords (continued)
| Key | Value | Details |
|---|---|---|
PROG_NAME |
String | Name of the process which triggered the event occurrence. Only available with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability. |
CURRENT_VALUE |
64 bit unsigned integer, in decimal | This key is only for AHAFS_THRESHOLD_VALUE event producers and will return the current value of the event at the time the event occurrence was detected. Note that due to delay between the time a process is notified and the time they read the event data, the actual current value of the event may have changed. |
RC_FROM_EVPROD |
32 bit integer, in decimal | This return code comes from the event producer either as the result of an error when trying to set up the event, or as the result of an event occurrence. Generally, return codes less than 256 indicate an error when attempting to register the event with the event producer. Some event producers will return codes greater than 256 to provide more information about the event occurrence. These return codes are documented in sys/ahafs_evProds.h |
BEGIN_EVPROD_INFO |
||
END_EVPROD_INFO |
String* |
These two keywords mark the beginning and end of the string returned by the event producer. There will always be a newline after BEGIN_EVPROD_INFO and before END_EVPROD_INFO. For consumers who have specified CLUSTER=YES, this is where node information will be given. |
STACK_TRACE |
String* |
For consumers who have specified INFO_LVL=3 with an event producer who has specified the AHAFS_STKTRACE_AVAILABLE capability, but not the AHAFS_CALLBACK_INTRCNTX capability, the stack trace of the event occurrence will be provided. The keyword STACK_TRACE indicates that the remaining event data, until the string END_EVENT_INFO is the stack of the event occurrence. |
NUM_EVDROPS_INTRCNTX |
Integer | This keyword represents the number of interrupt-context event occurrences that are dropped since the time that is specified by the TIME0_tvsec and TIME0_tvnsec keywords in the report. The event occurrences are dropped only when the frequency of the event occurrence is high. |
TIME0_tvsec |
||
TIME0_tvnsec |
Integer | These keywords record the time stamp of the first event-occurrence drop in seconds and nano-seconds since the Epoch. These keywords are reported along with the NUM_EVDROPS_INTRCNTX keyword. |
Duplicate Event Consolidation
If the same event occurs multiple times before the consumer has read the data, the duplicate entries will be consolidated into one entry. This consolidation is indicated by non sequential sequence numbers without a corresponding BUF_WRAP keyword. The timestamp and sequence numbers will reflect the most recent occurrence of the event.