Motr  M0
Cookie

Data Structures

struct  m0_cookie
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB
 
#define m0_cookie_of(cookie, type, field)
 
#define try_read(addr, dummy)
 

Functions

M0_INTERNAL bool m0_arch_addr_is_sane (const void *addr)
 
M0_INTERNAL int m0_arch_cookie_global_init (void)
 
M0_INTERNAL void m0_arch_cookie_global_fini (void)
 
M0_INTERNAL int m0_cookie_global_init (void)
 
M0_INTERNAL void m0_cookie_new (uint64_t *gen)
 
M0_INTERNAL void m0_cookie_init (struct m0_cookie *cookie, const uint64_t *obj)
 
M0_INTERNAL bool m0_addr_is_sane (const uint64_t *addr)
 
M0_INTERNAL bool m0_addr_is_sane_and_aligned (const uint64_t *addr)
 
M0_INTERNAL int m0_cookie_dereference (const struct m0_cookie *cookie, uint64_t **addr)
 
M0_INTERNAL bool m0_cookie_is_null (const struct m0_cookie *cookie)
 
M0_INTERNAL bool m0_cookie_is_eq (const struct m0_cookie *cookie1, const struct m0_cookie *cookie2)
 
M0_INTERNAL void m0_cookie_global_fini (void)
 
struct m0_cookie M0_XCA_DOMAIN (be|rpc)
 
M0_INTERNAL bool m0_arch_addr_is_sane (const uint64_t *addr)
 
static void sigsegv (int sig)
 

Variables

static uint64_t cookie_generation
 
M0_INTERNAL const struct m0_cookie M0_COOKIE_NULL
 
static const struct m0_panic_ctx signal_panic
 

Detailed Description

In a network-file-system, when a client queries for an in-memory object to a server, server searches through a set of data-structures to retrieve the object. Multiple queries asking for the same object lead to a repeated search.

Cookie mechanism avoids such redundant search operations. When the first query for an object arrives, server searches the object, embeds it's address in a cookie, and then sends this cookie to a client. Client then uses this cookie in subsequent queries for the same object.

As client is unaware of memory-updates at server-end, its necessary for server to verify that received cookie is not a stale one. Server achieves this by maintaining a global counter called generation-count. It embeds a same value of generation-count in an object and a cookie associated with it. On reception of a cookie, before returning a required object, server ensures that value of generation-count in the cookie matches with the one in the object.

The key data-structure in Lib-Cookie is m0_cookie. It holds the address of an object along with a generation-count which is used to check validity of a cookie.

The constructor of an object calls m0_cookie_new, which increments a global counter cookie_generation, and embeds it in the object. On arrival of a query for the object, m0_cookie_init creates a cookie, and embeds the address for the object in m0_cookie along with a copy of cookie_generation embedded in the object.

For subsequent requests for the same object, client communicates a cookie to a server. On server, function m0_cookie_dereference validates a cookie, and retrieves an address of the object for a valid cookie.

m0_cookie_dereference checks the validity of a cookie in two steps. The first step validates an address embedded inside the cookie. The second step ensures that the cookie is not stale. To identify a stale cookie, it compares its generation count with the generation count in the object. In order to reduce the probability of false validation, the function m0_cookie_global_init initializes the cookie_generation with the system-time during initialisation of Motr.

Macro Definition Documentation

◆ m0_cookie_of

#define m0_cookie_of (   cookie,
  type,
  field 
)
Value:
({ \
uint64_t *__gen; \
const struct m0_cookie *__cookie = (cookie); \
m0_cookie_dereference(__cookie, &__gen) != 0 ? NULL : \
container_of(__gen, type, field); \
})
#define NULL
Definition: misc.h:38
static int field(struct ff2c_context *ctx, struct ff2c_term *term)
Definition: parser.c:84
int type
Definition: dir.c:1031

A macro to retrive address of a parent structure, associated with an object embedded in a cookie.

Definition at line 121 of file cookie.h.

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_LIB

Definition at line 63 of file cookie.c.

◆ try_read

#define try_read (   addr,
  dummy 
)
Value:
({ \
long rc; \
mm_segment_t save_fs = get_fs(); \
\
set_fs(KERNEL_DS); \
pagefault_disable(); \
rc = __copy_from_user_inatomic(&(dummy), \
(__force typeof(dummy) __user *)(addr), \
sizeof(dummy)); \
pagefault_enable(); \
set_fs(save_fs); \
rc; \
})
static struct m0_be_active_record_domain dummy
Definition: active_record.c:35
Definition: xcode.h:73
int32_t rc
Definition: trigger_fop.h:47

Definition at line 29 of file kcookie.c.

Function Documentation

◆ m0_addr_is_sane()

M0_INTERNAL bool m0_addr_is_sane ( const uint64_t *  addr)

Checks if address is pointing to a valid memory location.

See also
m0_addr_is_sane_and_aligned()

Definition at line 99 of file cookie.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_addr_is_sane_and_aligned()

M0_INTERNAL bool m0_addr_is_sane_and_aligned ( const uint64_t *  addr)

Checks if address is aligned to 8-byte address and is pointing to a valid memory location.

See also
m0_addr_is_sane()

Definition at line 104 of file cookie.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_arch_addr_is_sane() [1/2]

M0_INTERNAL bool m0_arch_addr_is_sane ( const uint64_t *  addr)

Definition at line 44 of file kcookie.c.

◆ m0_arch_addr_is_sane() [2/2]

M0_INTERNAL bool m0_arch_addr_is_sane ( const void *  addr)

Checks the validity of an address by dereferencing the same. Occurrence of an error in case of an invalid address gets handled by the function sigsegv().

Definition at line 62 of file ucookie.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_arch_cookie_global_fini()

M0_INTERNAL void m0_arch_cookie_global_fini ( void  )

This function is intentionally kept blank.

Sets the signal handler for SIGSEGV to the default handler.

Definition at line 59 of file kcookie.c.

Here is the caller graph for this function:

◆ m0_arch_cookie_global_init()

M0_INTERNAL int m0_arch_cookie_global_init ( void  )

Sets the signal handler for SIGSEGV to sigsegv() function.

Definition at line 51 of file kcookie.c.

Here is the caller graph for this function:

◆ m0_cookie_dereference()

M0_INTERNAL int m0_cookie_dereference ( const struct m0_cookie cookie,
uint64_t **  addr 
)

Retrieves address of an object from a cookie.

Parameters
cookie(in) address of a cookie that holds the address of an object
addr(out) pointer to a memory location which holds retrieved address

Definition at line 109 of file cookie.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_cookie_global_fini()

M0_INTERNAL void m0_cookie_global_fini ( void  )

Definition at line 137 of file cookie.c.

Here is the call graph for this function:

◆ m0_cookie_global_init()

M0_INTERNAL int m0_cookie_global_init ( void  )

Initializes the gencount. Gets called during motr initialization.

Definition at line 77 of file cookie.c.

Here is the call graph for this function:

◆ m0_cookie_init()

M0_INTERNAL void m0_cookie_init ( struct m0_cookie cookie,
const uint64_t *  obj 
)

Embeds address of an object along with a generation-count in a cookie.

Parameters
cookie(out) address of a cookie in which obj gets embedded
obj(in) address of an object

Definition at line 90 of file cookie.c.

Here is the caller graph for this function:

◆ m0_cookie_is_eq()

M0_INTERNAL bool m0_cookie_is_eq ( const struct m0_cookie cookie1,
const struct m0_cookie cookie2 
)

Compares two cookies.

Definition at line 131 of file cookie.c.

Here is the caller graph for this function:

◆ m0_cookie_is_null()

M0_INTERNAL bool m0_cookie_is_null ( const struct m0_cookie cookie)

Returns 'true' when cookie is NULL.

Definition at line 125 of file cookie.c.

Here is the caller graph for this function:

◆ m0_cookie_new()

M0_INTERNAL void m0_cookie_new ( uint64_t *  gen)

Increments generation-count by one and assigns the same to *gen.

Definition at line 83 of file cookie.c.

Here is the caller graph for this function:

◆ M0_XCA_DOMAIN()

struct m0_cookie M0_XCA_DOMAIN ( be rpc)

◆ sigsegv()

static void sigsegv ( int  sig)
static

Signal handler for SIGSEGV.

Definition at line 46 of file ucookie.c.

Here is the call graph for this function:

Variable Documentation

◆ cookie_generation

uint64_t cookie_generation
static

Definition at line 66 of file cookie.c.

◆ M0_COOKIE_NULL

M0_INTERNAL const struct m0_cookie M0_COOKIE_NULL
Initial value:
= {
.co_generation = 0xffff,
.co_addr = 7,
}

Definition at line 68 of file cookie.c.

◆ signal_panic

const struct m0_panic_ctx signal_panic
static
Initial value:
= {
.pc_expr = "fatal signal delivered",
.pc_func = "unknown",
.pc_file = "unknown",
.pc_lineno = 0,
.pc_fmt = "signo: %i"
}

Definition at line 35 of file ucookie.c.