"Glusterfs Learning four": Automatically generate the required xlator in the Volfile

Source: Internet
Author: User
Tags glusterfs gluster

In the design of Gluster Xlator in the previous article, we talked about adding xlator functionality by manually modifying the Volfile, but the actual need to When the project is established, the corresponding xlator can be generated automatically in Volfile during the process of creating the volume, this article will discuss this problem.


I. Introduction of Volfile

This article mainly discusses the gluster of Volfile, then the main understanding of volfile definition and significance, there are two articles can be read:

Http://www.gluster.org/community/documentation/index.php/Understanding_vol-file

Http://blog.sina.com.cn/s/blog_6a4c492f0100qm6v.html

After that, I would like to talk about my own understanding and understanding.

volfile Deletion: the deletion of a volume causes Volfile to be deleted, that is, after the Gluster volume stop img and gluster volume delete img are executed.

volfile Generation:Volfile is generated by the server side when the volume is created, that is, after executing the gluster volume create IMG.

volfile Loading:volfile is loaded when the GLUSTERFSD server process executes, and GLUSTERFSD is in volume Start time (after create volume): Gluster volume start img.

What is the difference between glusterfs,glusterd,glusterfsd,gluster? Or want to say one's own understanding, to correct:
>glusterfs:client-side Mount server-side volumes and related operations on client side >glusterd:Gluster Elastic Volume Management daemon. Glusterd is related to volume management, and the code is centralized under XLATORS/MGMT/GLUSTERD/SRC. >GLUSTERFSD:start a glusterfs the server,server end of the process. >gluster:gluster concole manager,to Run the program and display Gluster prompt

Process to understand, or to go deep into the code in order to have a deeper understanding, or to constantly read the source code.


Second, automatically generate Volfile add content

after understanding the Volfile, we discuss its auto-generated problems. Similarly, we need to add audit function in Glusterfs, and join Audit Xlator, the previous article has said how to write audit code, then add to the source code of Glusterfs only need to modify some simple compilation file path, not much to say, Mainly about volfile related functions , there are three main:

>GLUSTERD-VOLGEN.C: Generate Volfile function

>glusterd-volgen.h

>glusterd-volume-set.c:volfile option settings related to

Let's look at the function Server_graph_builder that generates Xlator graph in GLUSTER-VOLGEN.C:

Static Intserver_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict,        void *param) {char *volname = NULL;        char *path = NULL;        int pump = 0;        xlator_t *XL = NULL;        xlator_t *TXL = NULL;        xlator_t *RBXL = NULL;        Char transt[16] = {0,};        char *ptranst = NULL;        Char volume_id[64] = {0,};        Char Tstamp_file[path_max] = {0,};        int ret = 0;        char *xlator = NULL;        char *loglevel = NULL;        char *username = NULL;        char *password = NULL;        Char Index_basepath[path_max] = {0};     Char key[1024] = {0};   glusterd_brickinfo_t *brickinfo = NULL;        Char Changelog_basepath[path_max] = {0,};        gf_boolean_t quota_enabled = _gf_true;        gf_boolean_t pgfid_feat = _gf_false;        char *value = NULL;        char *ssl_user = NULL;        Brickinfo = param;        Path = brickinfo->path;        Volname = volinfo->volname;        Get_vol_transport_type (Volinfo, transt);        ret = DICT_GET_STR (set_dict, "Xlator", &xlator); /* Got a CLI log level request */if (!ret) {ret = Dict_get_str (set_dict, "loglevel", &logleve                L); if (ret) {gf_log ("Glusterd", Gf_log_error, "Could not get both" "                        Translator name and loglevel for log level request ");                Goto out;        }} ret = Glusterd_volinfo_get (Volinfo, Vkey_features_quota, &value); if (valuE) {ret = Gf_string2boolean (value, "a_enabled");        if (ret) goto out;        } XL = Volgen_graph_add (graph, "Storage/posix", volname);        if (!XL) return-1;        ret = Xlator_set_option (XL, "directory", Path);        if (ret) return-1;        ret = Xlator_set_option (XL, "Volume-id", Uuid_utoa (volinfo->volume_id));        if (ret) return-1;        ret = CHECK_AND_ADD_DEBUG_XL (graph, set_dict, volname, "POSIX");        if (ret) return-1;        XL = volgen_graph_add (graph, "Features/access-control", volname);        if (!XL) return-1;        ret = CHECK_AND_ADD_DEBUG_XL (graph, set_dict, volname, "ACL");        if (ret) return-1;        XL = volgen_graph_add (graph, "features/locks", volname);        if (!XL) return-1; RET = Check_AND_ADD_DEBUG_XL (graph, set_dict, volname, "locks");        if (ret) return-1;        XL = volgen_graph_add (graph, "performance/io-threads", volname);        if (!XL) return-1;        ret = CHECK_AND_ADD_DEBUG_XL (graph, set_dict, Volname, "io-threads");        if (ret) return-1;        XL = volgen_graph_add (graph, "Features/barrier", volname);        if (!XL) return-1;        XL = volgen_graph_add (graph, "Features/quota", volname);        if (!XL) return-1;        ret = Xlator_set_option (XL, "Volume-uuid", volname); if (ret) return-1;/* Add the audit xlator to the graph*/XL = volgen_graph_add (graph, "Features/aud        It ", volname);        if (!XL) return-1;        ret = Xlator_set_option (XL, "Audit", "off");        if (ret) return-1; /* Check for read-only volume option, and add it to the graph */if (Dict_get_str_boolean (set_dicT, "Features.read-only", 0)) {XL = Volgen_graph_add (graph, "features/read-only", volname);                        if (!XL) {ret =-1;                Goto out;        }} XL = Volgen_graph_add_as (graph, "debug/io-stats", Path);        if (!XL) return-1;        XL = volgen_graph_add (graph, "Protocol/server", volname);        if (!XL) return-1;        ret = Xlator_set_option (XL, "Transport-type", transt); if (ret) return-1; Out:return ret;}
just select the main part of the code to illustrate, you can see that the Server_graph_builder function inside the relevant Xlator set generation sequence and the last generated Volfile file is consistent, The main thing is that two functions add Xlator to Volfile: Volgen_graph_add and Xlator_set_option, one is added to graph according to Volname, and the other is setting the associated option. In the line106~line112 of the code, you add the code of the xlator that you need to generate, and you're done. Of course, you need to add the corresponding code to the Get_server_xlator function in the glusterd-volgen.c file:

static        Glusterd_server_xlator_tget_server_xlator (char *xlator) {glusterd_server_xlator_t subvol = GF_XLATOR_NONE;        if (strcmp (Xlator, "posix") = = 0) Subvol = gf_xlator_posix;        if (strcmp (Xlator, "acl") = = 0) Subvol = gf_xlator_acl;        if (strcmp (xlator, "locks") = = 0) Subvol = gf_xlator_locks;        if (strcmp (Xlator, "io-threads") = = 0) Subvol = Gf_xlator_iot;        if (strcmp (xlator, "index") = = 0) Subvol = gf_xlator_index;        if (strcmp (xlator, "marker") = = 0) Subvol = gf_xlator_marker;        if (strcmp (Xlator, "io-stats") = = 0) Subvol = gf_xlator_io_stats; if (strcmp (Xlator, "bd") = = 0) Subvol = gf_xlator_bd;if (strcmp (Xlator, "audit") = = 0) Subvol = Gf_xlator_au        DIT; return subvol;} 
See Line22-line23. At this point, the GLUSTERD-VOLGEN.C code add modification is complete. Then add the macros in the Glusterd-volgen.h header file:

#define VKEY_FEATURE_AUDTI "Features.audit"
as well as in the glusterd_server_xlator_t structure: Gf_xlator_audit can be added.

look at gluster-volume-set.c This file, it is mainly to volfile in the Xlator option to set, in Glusterd_volopt_map Add code:

{    . Key   = "Features.audit",    . Voltype     = "Features/audit",    . Op_version  = 1,},
Finally, modify the volume_options in audit.c:

{. Key = {"Audit"},. Type = Gf_option_type_bool,. Default_value = "Off",}
after simple additions and modifications to the makefile, it is possible to compile and install it, because it is primarily the server side, which is done on the server side.

First uninstall:

Make uninstall make Distclean
Compile and install:

./configuremake && Make Install
Then, restart the glusterd process, stop the volume, delete the volume, create the volume, start the volume, and view the Volfile.

Service Glusterd Restartgluster Volume stop Imggluster Volume Delete imggluster volume create img Replica 2 10.23.85.48:/d Ata/gluster 10.23.85.49:/data/glustergluster Volume start img

There are two issues encountered when creating volume:

1 The ./data/gluster is already part of the volume and can be deleted.

2.Peer rejected, restart all glusterd of the server (workaround).

We can look at the created Volfile:



It is important to note that before the code has been modified to compile the installation, constantly delete the volume, create the volume, the boot volume repeatedly done many times, However, the volfile did not generate the desired xlator content, thought to be uninstalled during the uninstall process is not clean, the actual reason is not to restart the Glusterd process , Glusterd has always been an old process (the exact point is that the process started half a month ago). So Glusterd, although it was updated after uninstalling the build, we did not restart the Glusterd service, So, half a month ago, the old Glusterd process was not compiled by the modified source code (that is, before it was added to the glusterd-volgen.c), so the modified code didn't work, so no matter how I created the Create volume volume, The implementation of the old GLUSTERD-VOLGEN.C code flow, so there is no change, just as long as the restart Glusterd service is good, the implementation of the modified code of the process, the main or their understanding of the problem is not deep enough, the code is not sensitive.

Let's look at the effect of Gluster volume set on the problem. We set an option, the switch, to control whether the Xlator works, and by default it's off, so we'll look at the difference between off and on.

On the default off (that is, the audit operation is not enabled), we mount the run on the client and create the file at Mount point: Aa,bb,cc,dd and folder: Aa,bb,cc,dd, then remove AA and AA:

Touch AA bb cc dd mkdir AA BB cc DD

you can see the logs on the server side:


We enable the Audit feature:

Gluster Volume set img features.audit on

you can see the option value changed from off to on, the audit function is started, then restart the GLUSTERFSD, then delete the file bb and the folder BB operation, observe the server side of the log situation.


You can see clearly, after opening the audit function, the successful implementation of the review to delete files and folders operation.



Author: Yi Solo Show

Email:[email protected]

Annotated Source: http://blog.csdn.net/lavorange/article/details/45246175



"Glusterfs Learning four": Automatically generate the required xlator in the Volfile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.