2 Unix SMB/CIFS implementation.
3 Main metadata server / Spotlight routines
5 Copyright (C) Ralph Boehme 2012-2014
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.
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.
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/>.
25 #include "marshalling.h"
26 #include "lib/util/dlinklist.h"
27 #include "librpc/gen_ndr/mdssvc.h"
30 * glib uses TRUE and FALSE which was redefined by "includes.h" to be
31 * unusable, undefine so glib can establish its own working
36 /* allow building with --picky-developer */
37 #pragma GCC diagnostic push
38 #pragma GCC diagnostic ignored "-Wcast-qual"
40 #include <tracker-sparql.h>
41 #pragma GCC diagnostic pop
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
48 /******************************************************************************
49 * Some helper stuff dealing with queries
50 ******************************************************************************/
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 */
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 */
93 struct sl_inode_path_map {
94 struct mds_ctx *mds_ctx;
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 */
111 /******************************************************************************
112 * Function declarations
113 ******************************************************************************/
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,
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);
129 #endif /* _MDSSVC_H */