static struct meta1_service_url_s * __poll_services(struct meta1_backend_s *m1, guint replicas, struct compound_type_s *ct, guint seq, struct meta1_service_url_s **used, GError **err) { struct grid_lb_iterator_s *iter = NULL; struct service_info_s **siv = NULL; GRID_DEBUG("Polling %u [%s]", replicas, ct->fulltype); if (!(*err = _get_iterator(m1, ct, &iter))) { struct lb_next_opt_ext_s opt; memset(&opt, 0, sizeof(opt)); opt.req.distance = MACRO_COND(replicas>1,1,0); opt.req.max = replicas; opt.req.duplicates = FALSE; opt.req.stgclass = NULL; opt.req.strict_stgclass = TRUE; opt.srv_forbidden = __srvinfo_from_m1srvurl(m1->lb, ct->baretype, used); if (ct->req.k && !strcmp(ct->req.k, NAME_TAGNAME_USER_IS_SERVICE)) { gchar *srvurl = g_strdup_printf("1||%s|", ct->req.v); struct meta1_service_url_s *inplace[2] = { meta1_unpack_url(srvurl), NULL }; /* If ct->req.v is not an addr, srv_inplace will contain NULL */ opt.srv_inplace = __srvinfo_from_m1srvurl(m1->lb, NULL, inplace); opt.req.distance = 1; meta1_service_url_clean(inplace[0]); g_free(srvurl); } else { opt.filter.hook = _filter_tag; opt.filter.data = ct; } if (!grid_lb_iterator_next_set2(iter, &siv, &opt)) { EXTRA_ASSERT(siv == NULL); *err = NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "No service available"); } grid_lb_iterator_clean(iter); iter = NULL; g_slist_free_full(opt.srv_forbidden, (GDestroyNotify)service_info_clean); g_slist_free_full(opt.srv_inplace, (GDestroyNotify)service_info_clean); } if(NULL != *err) return NULL; struct meta1_service_url_s *m1u = _siv_to_url (siv); service_info_cleanv(siv, FALSE); siv = NULL; g_strlcpy(m1u->srvtype, ct->type, sizeof(m1u->srvtype)); m1u->seq = seq; return m1u; }
static struct meta1_service_url_s * __poll_services(struct meta1_backend_s *m1, guint replicas, struct compound_type_s *ct, guint seq, struct meta1_service_url_s **used, GError **err) { struct grid_lb_iterator_s *iter = NULL; struct service_info_s **siv = NULL; GRID_DEBUG("Polling %u [%s]", replicas, ct->fulltype); if (!(*err = _get_iterator(m1, ct, &iter))) { struct lb_next_opt_ext_s opt; memset(&opt, 0, sizeof(opt)); opt.req.distance = MACRO_COND(replicas>1,1,0); opt.req.max = replicas; opt.req.duplicates = FALSE; opt.req.stgclass = NULL; opt.req.strict_stgclass = TRUE; opt.srv_forbidden = __srvinfo_from_m1srvurl(m1->backend.lb, ct->baretype, used); opt.filter.hook = _filter_tag; opt.filter.data = ct; if (!grid_lb_iterator_next_set2(iter, &siv, &opt)) { EXTRA_ASSERT(siv == NULL); *err = NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "No service available"); } grid_lb_iterator_clean(iter); iter = NULL; g_slist_free_full(opt.srv_forbidden, (GDestroyNotify)service_info_clean); } if(NULL != *err) return NULL; struct meta1_service_url_s *m1u = _siv_to_url (siv); service_info_cleanv(siv, FALSE); siv = NULL; g_strlcpy(m1u->srvtype, ct->type, sizeof(m1u->srvtype)); m1u->seq = seq; return m1u; }
static GError * __relink_container_services(struct m1v2_relink_input_s *in, gchar ***out) { GError *err = NULL; struct service_info_s **polled = NULL; struct meta1_service_url_s *packed = NULL; struct meta1_service_url_s *ref = (in->kept && in->kept[0]) ? in->kept[0] : in->replaced[0]; /* check the services provided are those in place */ struct meta1_service_url_s **inplace = NULL; err = __get_container_all_services (in->sq3, in->url, ref->srvtype, &inplace); if (!err && !__match_urlv(inplace, in->kept, in->replaced)) err = NEWERROR(CODE_USER_INUSE, "services changed"); meta1_service_url_cleanv (inplace); inplace = NULL; /* it is time to poll */ if (!err) { struct service_update_policies_s *pol = meta1_backend_get_svcupdate(in->m1); EXTRA_ASSERT (pol != NULL); struct lb_next_opt_ext_s opt; memset (&opt, 0, sizeof (opt)); opt.req.max = service_howmany_replicas (pol, in->ct->baretype); opt.req.distance = opt.req.max > 1 ? 1 : 0; opt.req.duplicates = FALSE; opt.req.stgclass = NULL; opt.req.strict_stgclass = TRUE; opt.filter.hook = NULL; opt.filter.data = NULL; if (in->kept) opt.srv_inplace = __srvinfo_from_m1srvurl (in->m1->lb, in->ct->baretype, in->kept); if (in->replaced) opt.srv_forbidden = __srvinfo_from_m1srvurl (in->m1->lb, in->ct->baretype, in->replaced); if (g_slist_length(opt.srv_inplace) >= opt.req.max) err = NEWERROR(CODE_POLICY_NOT_SATISFIABLE, "Too many services kept"); if (!err) { if (!grid_lb_iterator_next_set2 (in->iterator, &polled, &opt)) { EXTRA_ASSERT(polled == NULL); err = NEWERROR (CODE_POLICY_NOT_SATISFIABLE, "No service available"); } else { EXTRA_ASSERT(polled != NULL); } } g_slist_free_full (opt.srv_forbidden, (GDestroyNotify)service_info_clean); g_slist_free_full (opt.srv_inplace, (GDestroyNotify)service_info_clean); } /* Services have been polled, them save them. * We MUST use the same SEQ number. Since the service are packed in one * entry, we can save them with a single SQL statement. */ if (!err && !in->dryrun) { packed = _siv_to_url (polled); packed->seq = ref->seq; strcpy (packed->srvtype, ref->srvtype); err = __save_service (in->sq3, in->url, packed, TRUE); } /* if the checks, polling and storage succeeded, prepare the output for * the caller */ if (!err) { struct meta1_service_url_s **newset = expand_url (packed); *out = pack_urlv (newset); meta1_service_url_cleanv (newset); } service_info_cleanv (polled, FALSE); meta1_service_url_clean (packed); return err; }