summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
blob: d377f09ac8082110254b9cec658b9550d47ef741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/*
  Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/


#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "rpc-clnt.h"
#include "glusterd1.h"
#include "gd-xdr.h"
#include "compat-errno.h"
#include "glusterd-op-sm.h"
#include "glusterd-sm.h"
#include "glusterd.h"
#include "protocol-common.h"
#include "glusterd-utils.h"
#include <sys/uio.h>


#define SERVER_PATH_MAX  (16 * 1024)


extern glusterd_op_info_t    opinfo;

int
glusterd_null (rpcsvc_request_t *req)
{
/*        gf_common_rsp rsp = {0,};

        rsp.gfs_id = req->gfs_id;
         //Accepted 
        rsp.op_ret = 0;

        server_submit_reply (NULL, req, &rsp, NULL, 0, NULL,
                             (gfs_serialize_t)xdr_serialize_common_rsp);
*/
        return 0;
}

int
glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov, 
                        int count, void *myframe)
{
        gd1_mgmt_probe_rsp    rsp   = {{0},};
        glusterd_conf_t       *conf = NULL;
        int                   ret   = 0;
        char                  str[50];
        glusterd_peerinfo_t           *peerinfo = NULL;
        glusterd_peerinfo_t           *dup_peerinfo = NULL;
        glusterd_friend_sm_event_t    *event = NULL;

        conf  = THIS->private;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gd_xdr_to_mgmt_probe_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                //rsp.op_ret   = -1;
                //rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received probe resp from uuid: %s, host: %s", 
                str, rsp.hostname);

        ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (!peerinfo->hostname) {
                glusterd_friend_find (NULL, rsp.hostname, &dup_peerinfo);
                GF_ASSERT (dup_peerinfo);
                GF_ASSERT (dup_peerinfo->hostname);
                peerinfo->hostname = gf_strdup (rsp.hostname);
                peerinfo->rpc = dup_peerinfo->rpc;
                list_del_init (&dup_peerinfo->uuid_list);
                GF_FREE (dup_peerinfo->hostname);
                GF_FREE (dup_peerinfo);
        }
        GF_ASSERT (peerinfo->hostname);
        uuid_copy (peerinfo->uuid, rsp.uuid);

        ret = glusterd_friend_sm_new_event 
                        (GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }

        event->peerinfo = peerinfo;
        event->ctx      = ((call_frame_t *)myframe)->local;
        ret = glusterd_friend_sm_inject_event (event);


        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        gf_log ("glusterd", GF_LOG_NORMAL, "Received resp to probe req");

        return ret;

out:
        return ret;
}

int
glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov, 
                            int count, void *myframe)
{
        gd1_mgmt_friend_rsp           rsp   = {{0},};
        glusterd_conf_t               *conf = NULL;
        int                           ret   = -1;
        glusterd_friend_sm_event_t        *event = NULL;
        glusterd_friend_sm_event_type_t    event_type = GD_FRIEND_EVENT_NONE;
        glusterd_peerinfo_t           *peerinfo = NULL;
        char                          str[50] = {0,};
        int32_t                       op_ret = -1;
        int32_t                       op_errno = -1;
        glusterd_probe_ctx_t          *ctx = NULL;

        conf  = THIS->private;

        if (-1 == req->rpc_status) {
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
        }

        ret = gd_xdr_to_mgmt_friend_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        op_ret = rsp.op_ret;
        op_errno = rsp.op_errno;

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received %s from uuid: %s, host: %s", 
                (op_ret)?"RJT":"ACC", str, rsp.hostname);

        ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (op_ret) 
                event_type = GD_FRIEND_EVENT_RCVD_RJT;
        else
                event_type = GD_FRIEND_EVENT_RCVD_ACC;

        ret = glusterd_friend_sm_new_event (event_type, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }
        event->peerinfo = peerinfo;

        ret = glusterd_friend_sm_inject_event (event);

        if (ret)
                goto out;

        ctx = ((call_frame_t *)myframe)->local;

        GF_ASSERT (ctx);

        ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno, 
                                            ctx->hostname);
        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

out:
        return ret;
}

int32_t
glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov, 
                              int count, void *myframe)
{
        gd1_mgmt_cluster_lock_rsp     rsp   = {{0},};
        int                           ret   = -1;
        int32_t                       op_ret = -1;
        glusterd_op_sm_event_t        *event = NULL;
        glusterd_op_sm_event_type_t    event_type = GD_OP_EVENT_NONE;
        glusterd_peerinfo_t           *peerinfo = NULL;
        char                          str[50] = {0,};

        GF_ASSERT (req);

        if (-1 == req->rpc_status) {
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
        }

        ret = gd_xdr_to_mgmt_cluster_lock_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        op_ret = rsp.op_ret;

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received %s from uuid: %s", 
                (op_ret)?"RJT":"ACC", str);

        ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (op_ret) 
                event_type = GD_OP_EVENT_RCVD_RJT;
        else
                event_type = GD_OP_EVENT_RCVD_ACC;

        ret = glusterd_op_sm_new_event (event_type, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }

        ret = glusterd_op_sm_inject_event (event);

        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        return ret;


out:
        return ret;
}

int32_t
glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov, 
                                 int count, void *myframe)
{
        gd1_mgmt_cluster_lock_rsp     rsp   = {{0},};
        int                           ret   = -1;
        int32_t                       op_ret = -1;
        glusterd_op_sm_event_t        *event = NULL;
        glusterd_op_sm_event_type_t    event_type = GD_OP_EVENT_NONE;
        glusterd_peerinfo_t           *peerinfo = NULL;
        char                          str[50] = {0,};


        GF_ASSERT (req);

        if (-1 == req->rpc_status) {
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
        }

        ret = gd_xdr_to_mgmt_cluster_unlock_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        op_ret = rsp.op_ret;

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received %s from uuid: %s", 
                (op_ret)?"RJT":"ACC", str);

        ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (op_ret) 
                event_type = GD_OP_EVENT_RCVD_RJT;
        else
                event_type = GD_OP_EVENT_RCVD_ACC;

        ret = glusterd_op_sm_new_event (event_type, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }

        ret = glusterd_op_sm_inject_event (event);

        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        return ret;


out:
        return ret;
}

int32_t
glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov, 
                          int count, void *myframe)
{
        gd1_mgmt_stage_op_rsp         rsp   = {{0},};
        int                           ret   = -1;
        int32_t                       op_ret = -1;
        glusterd_op_sm_event_t        *event = NULL;
        glusterd_op_sm_event_type_t    event_type = GD_OP_EVENT_NONE;
        glusterd_peerinfo_t           *peerinfo = NULL;
        char                          str[50] = {0,};


        GF_ASSERT (req);

        if (-1 == req->rpc_status) {
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
        }

        ret = gd_xdr_to_mgmt_stage_op_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        op_ret = rsp.op_ret;

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received %s from uuid: %s", 
                (op_ret)?"RJT":"ACC", str);

        ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (op_ret) 
                event_type = GD_OP_EVENT_RCVD_RJT;
        else
                event_type = GD_OP_EVENT_RCVD_ACC;

        ret = glusterd_op_sm_new_event (event_type, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }

        ret = glusterd_op_sm_inject_event (event);

        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        return ret;


out:
        return ret;
}

int32_t
glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, 
                          int count, void *myframe)
{
        gd1_mgmt_commit_op_rsp         rsp   = {{0},};
        int                           ret   = -1;
        int32_t                       op_ret = -1;
        glusterd_op_sm_event_t        *event = NULL;
        glusterd_op_sm_event_type_t    event_type = GD_OP_EVENT_NONE;
        glusterd_peerinfo_t           *peerinfo = NULL;
        char                          str[50] = {0,};


        GF_ASSERT (req);

        if (-1 == req->rpc_status) {
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
        }

        ret = gd_xdr_to_mgmt_commit_op_req (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                rsp.op_ret   = -1;
                rsp.op_errno = EINVAL;
                goto out;
        }
        uuid_unparse (rsp.uuid, str);

        op_ret = rsp.op_ret;

        gf_log ("glusterd", GF_LOG_NORMAL, 
                "Received %s from uuid: %s", 
                (op_ret)?"RJT":"ACC", str);

        ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo);

        if (ret) {
                GF_ASSERT (0);
        }

        if (op_ret) 
                event_type = GD_OP_EVENT_RCVD_RJT;
        else
                event_type = GD_OP_EVENT_RCVD_ACC;

        ret = glusterd_op_sm_new_event (event_type, &event);

        if (ret) {
                gf_log ("glusterd", GF_LOG_ERROR,
                         "Unable to get event");
                goto out;
        }

        ret = glusterd_op_sm_inject_event (event);

        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        return ret;


out:
        return ret;
}



int32_t
glusterd3_1_probe (call_frame_t *frame, xlator_t *this, 
                   void *data)
{
        gd1_mgmt_probe_req      req = {{0},};
        int                     ret = 0;
        char                    *hostname = NULL;
        glusterd_peerinfo_t     *peerinfo = NULL;
        glusterd_conf_t         *priv = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        hostname = data;
        priv = this->private;

        GF_ASSERT (priv);

        ret = glusterd_friend_find (NULL, hostname, &peerinfo);

        if (ret) {
                //We should not reach this state ideally
                GF_ASSERT (0);
                goto out; 
        }

        uuid_copy (req.uuid, priv->uuid);
        req.hostname = gf_strdup (hostname);

        ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
                                       GD_MGMT_PROBE_QUERY,
                                       NULL, gd_xdr_from_mgmt_probe_req,
                                       this, glusterd3_1_probe_cbk);

out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}


int32_t
glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this, 
                        void *data)
{
        gd1_mgmt_friend_req     req = {{0},};
        int                     ret = 0;
        glusterd_peerinfo_t     *peerinfo = NULL;
        glusterd_conf_t         *priv = NULL;
        glusterd_friend_sm_event_t     *event = NULL;
        glusterd_friend_req_ctx_t *ctx = NULL;


        if (!frame || !this || !data) {
                ret = -1;
                goto out;
        }

        event = data;
        priv = this->private;

        GF_ASSERT (priv);
        
        ctx = event->ctx;

        peerinfo = event->peerinfo;

        uuid_copy (req.uuid, priv->uuid);
        req.hostname = gf_strdup (peerinfo->hostname);

        ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
                                       GD_MGMT_FRIEND_ADD,
                                       NULL, gd_xdr_from_mgmt_friend_req,
                                       this, glusterd3_1_friend_add_cbk);

out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this, 
                           void *data)
{
        gd1_mgmt_cluster_lock_req       req = {{0},};
        int                             ret = 0;
        glusterd_peerinfo_t             *peerinfo = NULL;
        glusterd_conf_t                 *priv = NULL;
        call_frame_t                    *dummy_frame = NULL;
        int32_t                         pending_lock = 0;

        if (!this) {
                ret = -1;
                goto out;
        }

        priv = this->private;
        glusterd_get_uuid (&req.uuid);

        GF_ASSERT (priv);
        list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
                GF_ASSERT (peerinfo);

                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) 
                        continue;

                dummy_frame = create_frame (this, this->ctx->pool);

                if (!dummy_frame)
                        continue;

                ret = glusterd_submit_request (peerinfo, &req, dummy_frame, 
                                        priv->mgmt, GD_MGMT_CLUSTER_LOCK,
                                        NULL, 
                                        gd_xdr_from_mgmt_cluster_lock_req,
                                        this, glusterd3_1_cluster_lock_cbk);
                if (!ret)
                        pending_lock++;
                //TODO: Instead of keeping count, maintain a list of locked
                //UUIDs.
        }

        gf_log ("glusterd", GF_LOG_NORMAL, "Sent lock req to %d peers",
                                            pending_lock);
        opinfo.pending_count = pending_lock;
out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this, 
                            void *data)
{
        gd1_mgmt_cluster_lock_req       req = {{0},};
        int                             ret = 0;
        glusterd_peerinfo_t             *peerinfo = NULL;
        glusterd_conf_t                 *priv = NULL;
        int32_t                         pending_unlock = 0;
        call_frame_t                    *dummy_frame = NULL;

        if (!this ) {
                ret = -1;
                goto out;
        }

        priv = this->private;

        glusterd_get_uuid (&req.uuid);

        GF_ASSERT (priv);
        list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
                GF_ASSERT (peerinfo);

                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) 
                        continue;

                dummy_frame = create_frame (this, this->ctx->pool);

                if (!dummy_frame)
                        continue;

                ret = glusterd_submit_request (peerinfo, &req, dummy_frame, 
                                        priv->mgmt, GD_MGMT_CLUSTER_UNLOCK,
                                        NULL, 
                                        gd_xdr_from_mgmt_cluster_unlock_req,
                                        this, glusterd3_1_cluster_unlock_cbk);
                if (!ret)
                        pending_unlock++;
                //TODO: Instead of keeping count, maintain a list of locked
                //UUIDs.
        }

        gf_log ("glusterd", GF_LOG_NORMAL, "Sent unlock req to %d peers",
                                            pending_unlock);
        opinfo.pending_count = pending_unlock;

out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, 
                      void *data)
{
        gd1_mgmt_stage_op_req           *req = NULL;
        int                             ret = 0;
        glusterd_peerinfo_t             *peerinfo = NULL;
        glusterd_conf_t                 *priv = NULL;
        int32_t                         pending_peer = 0;
        int                             i = 0;
        call_frame_t                    *dummy_frame = NULL;

        if (!this) {
                ret = -1;
                goto out;
        }

        priv = this->private;

        GF_ASSERT (priv);

        for ( i = GD_OP_NONE; i < GD_OP_MAX; i++) {
                if (opinfo.pending_op[i])
                        break;
        }

        if (GD_OP_MAX == i) {

                //No pending ops, inject stage_acc

                glusterd_op_sm_event_t  *event = NULL;
        
                ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC, 
                                                &event);

                if (ret)
                        goto out;
        
                ret = glusterd_op_sm_inject_event (event);

                return ret;
        }


        ret = glusterd_op_build_payload (i, &req);

        if (ret)
                goto out;

        list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
                GF_ASSERT (peerinfo);

                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) 
                        continue;

                dummy_frame = create_frame (this, this->ctx->pool);

                if (!dummy_frame)
                        continue;

                ret = glusterd_submit_request (peerinfo, req, dummy_frame, 
                                                priv->mgmt, GD_MGMT_STAGE_OP,
                                                NULL, 
                                                gd_xdr_from_mgmt_stage_op_req,
                                                this, glusterd3_1_stage_op_cbk);
                if (!ret)
                        pending_peer++;
                //TODO: Instead of keeping count, maintain a list of pending 
                //UUIDs.
        }

        gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",
                                            pending_peer);
        opinfo.pending_count = pending_peer;

out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, 
                      void *data)
{
        gd1_mgmt_commit_op_req          *req = NULL;
        int                             ret = 0;
        glusterd_peerinfo_t             *peerinfo = NULL;
        glusterd_conf_t                 *priv = NULL;
        int32_t                         pending_peer = 0;
        int                             i = 0;
        call_frame_t                    *dummy_frame = NULL;

        if (!this) {
                ret = -1;
                goto out;
        }

        priv = this->private;

        GF_ASSERT (priv);

        for ( i = GD_OP_NONE; i < GD_OP_MAX; i++) {
                if (opinfo.pending_op[i])
                        break;
        }

        if (GD_OP_MAX == i) {

                //No pending ops, inject stage_acc

                glusterd_op_sm_event_t  *event = NULL;
        
                ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC, 
                                                &event);

                if (ret)
                        goto out;
        
                ret = glusterd_op_sm_inject_event (event);

                return ret;
        }


        ret = glusterd_op_build_payload (i, (gd1_mgmt_stage_op_req **)&req);

        if (ret)
                goto out;

        list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
                GF_ASSERT (peerinfo);

                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) 
                        continue;

                dummy_frame = create_frame (this, this->ctx->pool);

                if (!dummy_frame)
                        continue;

                ret = glusterd_submit_request (peerinfo, req, dummy_frame, 
                                                priv->mgmt, GD_MGMT_COMMIT_OP,
                                                NULL, 
                                                gd_xdr_from_mgmt_commit_op_req,
                                                this, glusterd3_1_commit_op_cbk);
                if (!ret)
                        pending_peer++;
                //TODO: Instead of keeping count, maintain a list of pending 
                //UUIDs.
        }

        gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",
                                            pending_peer);
        opinfo.pending_count = pending_peer;

out:
        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}


int
glusterd_handle_rpc_msg (rpcsvc_request_t *req)
{
        int     ret = -1;
        GF_ASSERT (req);

        //ret = glusterd1_mgmt_actors[req->procnum].actor (req);
        //

        switch (req->procnum) {
                case GD_MGMT_PROBE_QUERY:
                        ret = glusterd_handle_probe_query (req);
                        break;

                case GD_MGMT_FRIEND_ADD:
                        ret = glusterd_handle_incoming_friend_req (req);
                        break;

                case GD_MGMT_CLUSTER_LOCK:
                        ret = glusterd_handle_cluster_lock (req);
                        break;

                case GD_MGMT_CLUSTER_UNLOCK:
                        ret = glusterd_handle_cluster_unlock (req);
                        break;

                case GD_MGMT_STAGE_OP:
                        ret = glusterd_handle_stage_op (req);
                        break;

                case GD_MGMT_COMMIT_OP:
                        ret = glusterd_handle_commit_op (req);
                        break;

                case GD_MGMT_CLI_PROBE:
                        ret = glusterd_handle_cli_probe (req);
                        break;

                case GD_MGMT_CLI_CREATE_VOLUME:
                        ret = glusterd_handle_create_volume (req);
                        break;

                default:
                        GF_ASSERT (0);
        }

        if (!ret) {
                glusterd_friend_sm ();
                glusterd_op_sm ();
        }

        return ret;
}


rpcsvc_actor_t glusterd1_mgmt_actors[] = {
        [GD_MGMT_NULL]        = { "NULL",       GD_MGMT_NULL, glusterd_null, NULL, NULL},
        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_rpc_msg, NULL, NULL}, 
        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_rpc_msg, NULL, NULL}, 
        [GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_rpc_msg, NULL, NULL},
        [GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_rpc_msg, NULL, NULL},
        [GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_rpc_msg, NULL, NULL},
        [GD_MGMT_COMMIT_OP] = { "COMMIT_OP", GD_MGMT_COMMIT_OP, glusterd_handle_rpc_msg, NULL, NULL},
        [GD_MGMT_CLI_PROBE] = { "CLI_PROBE", GD_MGMT_CLI_PROBE, glusterd_handle_rpc_msg, NULL, NULL},
        [GD_MGMT_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GD_MGMT_CLI_CREATE_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
};

/*rpcsvc_actor_t glusterd1_mgmt_actors[] = {
        [GD_MGMT_NULL]        = { "NULL",       GD_MGMT_NULL, glusterd_null, NULL, NULL},
        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_probe_query, NULL, NULL}, 
        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL, NULL}, 
        [GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_cluster_lock, NULL, NULL},
        [GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_cluster_unlock, NULL, NULL},
        [GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_stage_op, NULL, NULL},
        [GD_MGMT_COMMIT_OP] = { "COMMIT_OP", GD_MGMT_COMMIT_OP, glusterd_handle_commit_op, NULL, NULL},
        [GD_MGMT_CLI_PROBE] = { "CLI_PROBE", GD_MGMT_CLI_PROBE, glusterd_handle_cli_probe, NULL, NULL},
};*/


struct rpcsvc_program glusterd1_mop_prog = {
        .progname  = "GlusterD0.0.1",
        .prognum   = GLUSTERD1_MGMT_PROGRAM,
        .progver   = GLUSTERD1_MGMT_VERSION,
        .numactors = GLUSTERD1_MGMT_PROCCNT,
        .actors    = glusterd1_mgmt_actors,
        .progport  = 4284,
};


struct rpc_clnt_procedure glusterd3_1_clnt_mgmt_actors[GD_MGMT_MAXVALUE] = {
        [GD_MGMT_NULL]        = {"NULL", NULL },
        [GD_MGMT_PROBE_QUERY]  = { "PROBE_QUERY",  glusterd3_1_probe},
        [GD_MGMT_FRIEND_ADD]  = { "FRIEND_ADD",  glusterd3_1_friend_add },
        [GD_MGMT_CLUSTER_LOCK] = {"CLUSTER_LOCK", glusterd3_1_cluster_lock},
        [GD_MGMT_CLUSTER_UNLOCK] = {"CLUSTER_UNLOCK", glusterd3_1_cluster_unlock},
        [GD_MGMT_STAGE_OP] = {"STAGE_OP", glusterd3_1_stage_op},
        [GD_MGMT_COMMIT_OP] = {"COMMIT_OP", glusterd3_1_commit_op},
//        [GF_FOP_GETSPEC]     = { "GETSPEC",   client_getspec, client_getspec_cbk },
};



struct rpc_clnt_program glusterd3_1_mgmt_prog = {
        .progname = "Mgmt 3.1",
        .prognum  = GLUSTERD1_MGMT_PROGRAM,
        .progver  = GLUSTERD1_MGMT_VERSION,
        .proctable    = glusterd3_1_clnt_mgmt_actors,
        .numproc  = GLUSTERD1_MGMT_PROCCNT,
};