+ All Categories
Home > Documents > GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel...

GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel...

Date post: 31-Jan-2018
Category:
Upload: trinhnhi
View: 215 times
Download: 0 times
Share this document with a friend
26
Kaleb KEITHLEY 1 GlusterFS as a Development Platform (Tips For Writing a GlusterFS Translator) Kaleb KEITHLEY Red Hat 8 June, 2012
Transcript
Page 1: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY1

GlusterFS as a Development Platform (Tips For Writing a GlusterFS Translator)

Kaleb KEITHLEYRed Hat8 June, 2012

Page 2: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY2

Extending GlusterFS with Translators

● What is a translator?● An example: the HekaFS uidmap translator● Translator basics● Translator file-ops (fops) methods● Inside fop methods — the nuts and bolts● Building in-tree or out-of-tree● Resources

Page 3: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY3

What is a GlusterFS translator

● Pluggable software component● Provision Storage == Create a directed graph of

translators● Linear, e.g. trivial one brick volume, NFS volume● Trees, e.g. Distribution, replication, stripe

● Translators are on both the server and on the client● Translators may be moved from client to server and vice

versa● Every translator implements the same API and ABI

Page 4: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY4

Simple Translator Stack — Linear

protocol/server

debug/io-stats

features/marker

performance/io-threads

features/locks

features/access-control

storage/posix protocols/client

performance/write-behind

performance/read-ahead

performance/io-cache

performance/quick-read

Performance/stat-prefetch

Debug/io-stats

Page 5: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY5

Complex Translator Stack — Distribute (DHT)

protocol/server

debug/io-stats

features/access-control

storage/posix

...

performance/stat-prefetch

debug/io-stats

cluster/distribute

performance/write-behind

protocol/clientprotocol/client

...

protocol/server

debug/io-stats

features/access-control

storage/posix

...

Page 6: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY6

nfs/server

Complex Translator Stack — DHT + NFS

protocol/server

debug/io-stats

features/access-control

storage/posix

...

performance/stat-prefetch

debug/io-stats

cluster/distribute

performance/write-behind

protocol/clientprotocol/client

...

protocol/server

debug/io-stats

features/access-control

storage/posix

...

nfs clients

Page 7: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY7

An example: HekaFS uidmap translator

● Consider a service provider with several customers● Each customer has thousands of users● Collisions in the uid and gid space

● Uidmap xlator maps uids and gids to discrete sets of uids and gids per tenant

Tenant red512 513 516Tenant green

511 512 515

Tenant blue513 515 516

/export/bricks/vol/export/bricks/vol/green/export/bricks/vol/red/export/bricks/vol/blue

uidmapxlator

Page 8: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY8

Translator basics

● Translators are shared objects (shlibs)● Methods

● int32_t init(xlator_t *this);● void fini(xlator_t *this);

● Data● struct xlator_fops fops { ... };● struct xlator_cbks cbks { };● struct volume_options options [] = { ... };

● Client, Server, Client/Server● Threads: write MT-SAFE● Portability: GlusterFS != Linux only● License: server GPLv3+, client GPLv2 or LGPLv3+

Page 9: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY9

Volume Options

struct volume_options options[] = { { .key = {"uidmap-plugin", "plugin"}, .type = GF_OPTION_TYPE_STR, }, { .key = {"root-squash"}, .type = GF_OPTION_TYPE_STR, .value = { "yes", "no"} }, { .key = {"uid-range"}, .type = GF_OPTION_TYPE_STR, }, { .key = {"gid-range"}, .type = GF_OPTION_TYPE_STR, }, { .key = {NULL} },};

GF_OPTION_TYPE_{ANY,STR,INT,SIZET,PERCENT,BOOL,...}

Page 10: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY10

Translator fops

● Here there be dragons (and they're not dragons of good fortune)

● Every fop method has a different signature● Signatures change from release to release● Documentation? :-(

● The nuts and bolts● fop methods and fop callbacks● STACK_WIND(), STACK_UNWIND(), and friends● Calling multiple “children”● Dealing with errors

● Indicating an I/O error● Indicating a Method error

Page 11: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY11

Every method has a different signature

● Open fop method and callbacktypedef int32_t (*fop_open_t) (call_frame_t *, xlator_t *, loc_t *, int32_t, fd_t *, dict_t *);

typedef int32_t (*fop_open_cbk_t) (call_frame_t *, void *, xlator_t *, int32_t, int32_t, fd_t *, dict_t *);

● Rename fop method and callbacktypedef int32_t (*fop_rename_t) (call_frame_t *, xlator_t *, loc_t *, loc_t *, dict_t *);

typedef int32_t (*fop_rename_cbk_t) (call_frame_t , void *, xlator_t *, int32_t, int32_t, struct iatt *, struct iatt *, struct iatt *, struct iatt *, struct iatt *);

Page 12: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY12

Method signatures change from release to release● 3.2 rename fop

typedef int32_t (*fop_open_t) (call_frame_t *, xlator_t *, loc_t *, int32_t, fd_t *, int32_t);

● 3.3 rename foptypedef int32_t (*fop_open_t) (call_frame_t *, xlator_t *, loc_t *, int32_t, fd_t *, dict_t *);

Page 13: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY13

Translator Data Types

● call_frame_t — ● xlator_t — translator context● inode_t — represents a file on disk; ref-counted● fd_t — represents an open file; ref-counted● iatt_t — ~= struct stat● dict_t — ~= Python dict (or C++ std::map)

Page 14: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY14

Utility Functions

● Memory Management● GF_MALLOC, GF_CALLOC, GF_FREE

● Logging● gf_log, gf_print_trace

● Red-black trees, hashes, etc

Page 15: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY15

fop methods and fop callbacks

uidmap_writev (...)

{

...

STACK_WIND (frame, uidmap_writev_cbk,

FIRST_CHILD (this),FIRST_CHILD (this)->fops->writev,fd, vector, count, offset, iobref);

/* DANGER ZONE */

return 0;

}

● Effectively lost control after STACK_WIND● Callback might have already happened● Or might be running right now● Or maybe it's not going to run 'til later

Page 16: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY16

fop methods and fop callback methods, cont.

uidmap_writev_cbk (call_frame_t *frame, void *cookie, ...)

{

...

STACK_UNWIND_STRICT (writev, frame

op_ret, op_errno, prebuf, postbuf);

return 0;

}

● The I/O is complete when the callback is called

Page 17: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY17

STACK_WIND versus STACK_WIND_COOKIE

● Pass extra data to the cbk with STACK_WIND_COOKIEquota_statfs (call_frame_t *frame,

xlator_t *this, loc_t *loc)

{

inode_t *root_inode = loc->inode->table->root;

STACK_WIND_COOKIE (frame, quota_statfs_cbk,

root_inode, FIRST_CHILD (this),

FIRST_CHILD (this)->fops->statfs, loc, xdata);

return 0;

}

● There is also frame->local● shared by all STACK_WIND callbacks

Page 18: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY18

STACK_WIND, STACK_WIND_COOKIE, cont.

● Pass extra data to the cbk with STACK_WIND_COOKIEquota_statfs_cbk (call_frame_t *frame, void *cookie, ...)

{

inode_t *root_inode = cookie;

...

}

Page 19: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY19

STACK_UNWIND versus STACK_UNWIND_STRICT

● STACK_UNWIND_STRICT uses the correct type/* return from function in a type-safe way */

#define STACK_UNWIND (frame, params ...)

do {

ret_fn_t fn = frame->ret;...

versus#define STACK_UNWIND_STRICT (op, frame, params ...)

do {

fop_##op##_cbk_t fn = (fop_##op##_cbk_t)frame->ret;...

● And why wouldn't you want strong typing?

Page 20: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY20

Calling multiple children (fan out)

afr_writev_wind (...)

{

...

for (i = 0; i < priv->child_count; i++) {

if (local->transaction.pre_op[i]) {

STACK_WIND_COOKIE (frame, afr_writev_wind_cbk,(void *) (long) i,priv->children[i],priv->children[i]->fops->writev,local->fd, ...);

}

}

return 0;

}

Page 21: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY21

Calling multiple children, cont. (fan in)

afr_writev_wind_cbk (...)

{

LOCK (&frame->lock);

callcnt = --local->call_count;

UNLOCK (&frame->lock);

if (callcnt == 0) /* we're done */

...

}

● failure by any one child means the whole transaction failed

● And needs to be handled accordingly

Page 22: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY22

Dealing With Errors: I/O errors

uidmap_writev_cbk (call_frame_t *frame, void *cookie,

xlator_t *this, int32_t op_ret, int32_t op_errno, ...)

{

...

STACK_UNWIND_STRICT (writev, frame, -1, EIO, ...);

return 0;

}

● op_ret: 0 or -1, success or failure● op_errno: from <errno.h>

● Use an op_errno that's valid and/or relevant for the fop

Page 23: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY23

Dealing With Errors: method errors

uidmap_writev (call_frame_t *frame, xlator_t *this, ...)

{

...

if (horrible_logic_error_must_abort) {

goto error; /* glusterfs idiom */

}

STACK_WIND(frame, uid_writev_cbk, ...);

return 0;

error:

STACK_UNWIND_STRICT (writev, frame, -1, EIO, NULL, NULL);

return 0;

}

Page 24: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY24

Building: in-tree or out-of-tree

● In-tree: Gluster.org source hasn't had a -devel package.

● Good news: starting with 3.3.0 there is now a -devel package if you build the RPM from the glusterfs.spec(.in) file included in the source

● Bad news: unclear what .deb packagers are doing● Fedora RPMs have had a -devel package for 3.2.x

● Use HekaFS sources as a model for building out-of-tree

Page 25: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY25

Resources● Jeff Darcy's HekaFS.org Translator tutorials

● http://hekafs.org/index.php/2011/11/translator-101-class-1-setting-the-stage/● http://hekafs.org/index.php/2011/11/translator-101-lesson-2-init-fini-and-private-context/● http://hekafs.org/index.php/2011/11/translator-101-lesson-3-this-time-for-real/● http://hekafs.org/index.php/2011/11/translator-101-lesson-4-debugging-a-translator/

● GlusterFS documentation● http://www.gluster.org/community/documentation/index.php/Main_Page

● GlusterFS Git repos● https://github.com/gluster/glusterfs● ssh://git.gluster.com/glusterfs.git

● This presentation http://www.fedorapeople.org/kkeithle/LinuxCon-Gluster.odp

● My email mailto:[email protected]

Page 26: GlusterFS as a Development Platform · PDF fileIn-tree: Gluster.org source hasn't had a -devel package

Kaleb KEITHLEY26

Call to action

● Go forth and write GlusterFS translators!


Recommended