Revert "vfs_glusterfs: explain that/why we use the raw tevent_context in init_gluster...
[samba.git] / source3 / rpc_server / mdssvc / mdssvc.h
1 /*
2    Unix SMB/CIFS implementation.
3    Main metadata server / Spotlight routines
4
5    Copyright (C) Ralph Boehme                   2012-2014
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _MDSSVC_H
22 #define _MDSSVC_H
23
24 #include "dalloc.h"
25 #include "marshalling.h"
26 #include "lib/util/dlinklist.h"
27 #include "librpc/gen_ndr/mdssvc.h"
28
29 /*
30  * glib uses TRUE and FALSE which was redefined by "includes.h" to be
31  * unusable, undefine so glib can establish its own working
32  * replacement.
33  */
34 #undef TRUE
35 #undef FALSE
36 /* allow building with --picky-developer */
37 #pragma GCC diagnostic push
38 #pragma GCC diagnostic ignored "-Wcast-qual"
39 #include <gio/gio.h>
40 #include <tracker-sparql.h>
41 #pragma GCC diagnostic pop
42
43 #define MAX_SL_FRAGMENT_SIZE 0xFFFFF
44 #define MAX_SL_RESULTS 100
45 #define MAX_SL_RUNTIME 30
46 #define MDS_TRACKER_ASYNC_TIMEOUT_MS 250
47
48 /******************************************************************************
49  * Some helper stuff dealing with queries
50  ******************************************************************************/
51
52 /* query state */
53 typedef enum {
54         SLQ_STATE_NEW,       /* Query received from client         */
55         SLQ_STATE_RUNNING,   /* Query dispatched to Tracker        */
56         SLQ_STATE_RESULTS,   /* Async Tracker query read           */
57         SLQ_STATE_FULL,      /* the max amount of result has beed queued */
58         SLQ_STATE_DONE,      /* Got all results from Tracker       */
59         SLQ_STATE_END,       /* Query results returned to client   */
60         SLQ_STATE_ERROR      /* an error happended somewhere       */
61 } slq_state_t;
62
63 /* query structure */
64 struct sl_query {
65         struct sl_query *prev, *next;    /* list pointers */
66         struct mds_ctx  *mds_ctx;        /* context handle */
67         slq_state_t      state;          /* query state */
68         struct timeval   start_time;     /* Query start time */
69         struct timeval   last_used;      /* Time of last result fetch */
70         struct timeval   expire_time;    /* Query expiration time */
71         struct tevent_timer *te;         /* query timeout */
72         int              snum;           /* share snum  */
73         uint64_t         ctx1;           /* client context 1 */
74         uint64_t         ctx2;           /* client context 2 */
75         sl_array_t      *reqinfo;        /* array with requested metadata */
76         const char      *query_string;   /* the Spotlight query string */
77         const char      *sparql_query;   /* the SPARQL query string */
78         uint64_t        *cnids;          /* restrict query to these CNIDs */
79         size_t           cnids_num;      /* Size of slq_cnids array */
80         const char      *path_scope;     /* path to directory to search */
81         GCancellable    *gcancellable;
82         TrackerSparqlCursor *tracker_cursor; /* Tracker SPARQL query result cursor */
83         struct sl_rslts *query_results;  /* query results */
84         TALLOC_CTX      *entries_ctx;    /* talloc parent of the search results */
85 };
86
87 struct sl_rslts {
88         int                num_results;
89         sl_cnids_t        *cnids;
90         sl_array_t        *fm_array;
91 };
92
93 struct sl_inode_path_map {
94         struct mds_ctx    *mds_ctx;
95         uint64_t           ino;
96         char              *path;
97 };
98
99 struct mds_ctx {
100         struct dom_sid sid;
101         uid_t uid;
102         const char *spath;
103         GCancellable *gcancellable;
104         TrackerSparqlConnection *tracker_con;
105         GMainContext *gcontext;
106         GMainLoop *gmainloop;
107         struct sl_query *query_list;     /* list of active queries */
108         struct db_context *ino_path_map; /* dbwrap rbt for storing inode->path mappings */
109 };
110
111 /******************************************************************************
112  * Function declarations
113  ******************************************************************************/
114
115 /*
116  * mdssvc.c
117  */
118 extern bool mds_init(struct messaging_context *msg_ctx);
119 extern bool mds_shutdown(void);
120 extern struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx,
121                                     const struct auth_session_info *session_info,
122                                     const char *path);
123 extern int mds_ctx_destructor_cb(struct mds_ctx *mds_ctx);
124 extern bool mds_dispatch(struct mds_ctx *query_ctx,
125                          struct mdssvc_blob *request_blob,
126                          struct mdssvc_blob *response_blob);
127 extern char *mds_dalloc_dump(DALLOC_CTX *dd, int nestinglevel);
128
129 #endif /* _MDSSVC_H */