[Spice-devel] [PATCH xf86-qxl] drm: fail gracefuly on monitor resize

2014-08-08 Thread Marc-André Lureau
If drmModeSetCrtc() failed, try to fallback to previous working
configuration.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1127552
---
 src/qxl_drmmode.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/qxl_drmmode.c b/src/qxl_drmmode.c
index f9eca5f..42347e6 100644
--- a/src/qxl_drmmode.c
+++ b/src/qxl_drmmode.c
@@ -214,11 +214,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr 
mode,
}
ret = drmModeSetCrtc(drmmode->fd, 
drmmode_crtc->mode_crtc->crtc_id,
 fb_id, x, y, output_ids, output_count, 
&kmode);
-   if (ret)
+   if (ret) {
xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
   "failed to set mode: %s", strerror(-ret));
-   else
+   return FALSE;
+   } else {
ret = TRUE;
+   }
 
if (crtc->scrn->pScreen)
xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
@@ -825,8 +827,9 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int 
height)
xf86CrtcPtr crtc = xf86_config->crtc[i];
if (!crtc->enabled)
continue;
-   drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
-  crtc->x, crtc->y);
+   if (!drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
+crtc->x, crtc->y))
+goto fail;
}
 
{
-- 
1.9.3

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH drm] qxl: don't create too large primary surface

2014-08-08 Thread Marc-André Lureau
Limit primary to qemu vgamem size, to avoid reaching
qemu guest bug "requested primary larger than framebuffer"
on resizing screen too large to fit.

Remove unneeded and misleading variables.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1127552

Signed-off-by: Marc-André Lureau 
---
 drivers/gpu/drm/qxl/qxl_display.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_display.c 
b/drivers/gpu/drm/qxl/qxl_display.c
index 5d7ea24..98a344c 100644
--- a/drivers/gpu/drm/qxl/qxl_display.c
+++ b/drivers/gpu/drm/qxl/qxl_display.c
@@ -523,7 +523,6 @@ static int qxl_crtc_mode_set(struct drm_crtc *crtc,
struct qxl_framebuffer *qfb;
struct qxl_bo *bo, *old_bo = NULL;
struct qxl_crtc *qcrtc = to_qxl_crtc(crtc);
-   uint32_t width, height, base_offset;
bool recreate_primary = false;
int ret;
int surf_id;
@@ -553,9 +552,10 @@ static int qxl_crtc_mode_set(struct drm_crtc *crtc,
if (qcrtc->index == 0)
recreate_primary = true;
 
-   width = mode->hdisplay;
-   height = mode->vdisplay;
-   base_offset = 0;
+   if (bo->surf.stride * bo->surf.height > qdev->vram_size) {
+   DRM_ERROR("Mode doesn't fit in vram size (vgamem)");
+   return -EINVAL;
+}
 
ret = qxl_bo_reserve(bo, false);
if (ret != 0)
@@ -569,10 +569,10 @@ static int qxl_crtc_mode_set(struct drm_crtc *crtc,
if (recreate_primary) {
qxl_io_destroy_primary(qdev);
qxl_io_log(qdev,
-  "recreate primary: %dx%d (was %dx%d,%d,%d)\n",
-  width, height, bo->surf.width,
-  bo->surf.height, bo->surf.stride, bo->surf.format);
-   qxl_io_create_primary(qdev, base_offset, bo);
+  "recreate primary: %dx%d,%d,%d\n",
+  bo->surf.width, bo->surf.height,
+  bo->surf.stride, bo->surf.format);
+   qxl_io_create_primary(qdev, 0, bo);
bo->is_primary = true;
}
 
-- 
1.9.3

___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH] [spice-gtk] fix bug: g_key_get_string() of vd_agent failed when keystring contains '['

2014-08-08 Thread Cody Chan
See here:
http://lists.freedesktop.org/archives/spice-devel/2014-August/017180.html

​---
 gtk/channel-main.c | 45 +++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 7a299a4..26dad7f 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -2656,6 +2656,43 @@ static void file_xfer_completed(SpiceFileXferTask
*task, GError *error)
 task->pending = TRUE;
 }

+/**
+ * g_string_replace:
+ * @src: original string
+ * @old_string: substring you want to replace
+ * @new_string: string you want to replace with
+ *
+ * Replace all @old_string with @new_string in @src.
+ *
+ * Returns: %NULL if any of @src/@old_string/@new_string is illegal
+ **/
+gchar *g_string_replace(const gchar *src, const gchar *old_string, const
gchar *new_string)
+{
+if (!src || !old_string || !new_string || !g_strcmp0(src, "") ||
+!g_strcmp0(old_string, ""))
+return NULL;
+gchar *retstr = NULL;
+gchar *srcstr = g_strdup(src);
+gchar *ptr = g_strstr_len(srcstr, strlen(srcstr), old_string);
+if (ptr != NULL){
+gchar *after = g_string_replace(ptr + strlen(old_string),
old_string, new_string);
+gchar *before = g_strndup(srcstr, ptr - srcstr);
+retstr = g_strconcat(before, new_string, after, NULL);
+g_free(after);
+g_free(before);
+g_free(srcstr);
+return retstr;
+}
+return g_strdup(src);
+}
+
+gchar *g_key_string_replace(const gchar *string, const gchar *group_name)
+{
+gchar *old_group_name = g_strconcat("[", group_name, "]", NULL);
+gchar *new_group_name = g_strconcat("<", group_name, ">", NULL);
+return g_string_replace(string, old_group_name, new_group_name);
+}
+
 static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res,
gpointer data)
 {
 GFileInfo *info;
@@ -2665,7 +2702,7 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
 gchar *basename = NULL;
 VDAgentFileXferStartMessage msg;
 gsize /*msg_size*/ data_len;
-gchar *string;
+gchar *string, *new_string;
 SpiceFileXferTask *task = (SpiceFileXferTask *)data;

 task->pending = FALSE;
@@ -2687,6 +2724,9 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
 /* Save keyfile content to memory. TODO: more file attributions
need to be sent to guest */
 string = g_key_file_to_data(keyfile, &data_len, &error);
+
+/* For each group_name do this */
+new_string = g_key_string_replace(string, "vdagent-file-xfer");
 g_key_file_free(keyfile);
 if (error)
 goto failed;
@@ -2695,8 +2735,9 @@ static void file_xfer_info_async_cb(GObject *obj,
GAsyncResult *res, gpointer da
 msg.id = task->id;
 agent_msg_queue_many(task->channel, VD_AGENT_FILE_XFER_START,
  &msg, sizeof(msg),
- string, data_len + 1, NULL);
+ new_string, data_len + 1, NULL);
 g_free(string);
+g_free(new_string);
 spice_channel_wakeup(SPICE_CHANNEL(task->channel), FALSE);
 return;

-- ​

-- 
QSBDT0RFUiBGUk9NIFJJRVNUIE9GIENUU0VV
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Spice-devel] [PATCH] [vd_agent] fix bug: g_key_get_string() of vd_agent failed when keystring contains '['

2014-08-08 Thread Cody Chan
Hi, as you can see, in vd_agent/file_xfer.cpp, it implemented
the g_key_get_string,
but I find a problem, when dragging a file with a name containing '[' (like
te[st.txt), it will be failed.
>From source code,
>next_group_pos = strstr(group_pos + strlen(group_pfx), "[");
>if (next_group_pos && key_pos > next_group_pos) return false;
we know that it tries to find the end of current group by '[' label,
if we drag a file like te[st.txt, the key_string many like:
[vdagent-file-xfer]
name=te[st.txt
size=10
so, it's failed when meta parsing and
returns VD_AGENT_FILE_XFER_STATUS_ERRO message.

I find a way to fix it, just replace '[' ']' with '<' '>' between group
name,
for it's illegal for windows to create a file with a name containing
'<'/'>'.

And of course, both vd_agent and spice-gtk should be patched.

---
 vdagent/file_xfer.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
index e402eb2..6998901 100644
--- a/vdagent/file_xfer.cpp
+++ b/vdagent/file_xfer.cpp
@@ -188,13 +188,13 @@ bool FileXfer::g_key_get_string(char* data, const
char* group, const char* key,
 char *group_pos, *key_pos, *next_group_pos, *start, *end;
 unsigned len;

-snprintf(group_pfx, sizeof(group_pfx), "[%s]", group);
+snprintf(group_pfx, sizeof(group_pfx), "<%s>", group);
 if (!(group_pos = strstr((char*)data, group_pfx))) return false;

 snprintf(key_pfx, sizeof(key_pfx), "\n%s=", key);
 if (!(key_pos = strstr(group_pos, key_pfx))) return false;

-next_group_pos = strstr(group_pos + strlen(group_pfx), "[");
+next_group_pos = strstr(group_pos + strlen(group_pfx), "<");
 if (next_group_pos && key_pos > next_group_pos) return false;

 start = key_pos + strlen(key_pfx);
-- 

-- 
QSBDT0RFUiBGUk9NIFJJRVNUIE9GIENUU0VV
___
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/spice-devel